Perhaps you were confused by this in the documentation 
<https://golang.org/pkg/regexp/#Regexp.FindSubmatch>:
"...and the matches, if any, of its subexpressions, as defined by the 
'Submatch' descriptions in the package comment"

That means one value per actual parenthesised subexpression in the original 
expression. e.g. given expression ((\S+) (\S+) (\S+)) the results will be 
"aaa bbb ccc", "aaa", "bbb", "ccc".

((\S+) (\S+) (\S+)) 
^^     ^     ^
||     |     |
|$2    $3    $4
|
$1

But if one parenthesised expression matches multiple times due to a repeat, 
it still gives a single value (the last match).  That is: $1 is always $1, 
and $2 is always $2, based on their positions in the regexp.  They don't 
shift along if there are multiple matches.

Maybe you want FindAllSubmatch 
<https://golang.org/pkg/regexp/#Regexp.FindAllSubmatch> instead.
https://play.golang.org/p/vOIvg-r4EI1

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/de698d16-c190-46e1-8f51-04c6ddba3ced%40googlegroups.com.

Reply via email to