Is there a way in Go Regex if I have (a)|(b) to start groups for b also with 0 ? how would I do that?
re := regexp.MustCompile(
`<(\$)([a-zA-Z0-9]+):([a-zA-Z0-9]+):([a-zA-Z0-9]+)>|{(@)([a-zA-Z0-9 ]+)}`)
and iterate over with
for _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {
...
}
How do I "normalize" groups (indexes)? so the (@) is also group 0?
Can i use groupnames with the same names?
Go regex engine is RE2, and infortunately it does not support the feature you are looking for, namely, a branch reset group.
There are PCRE library ports for Go if you need it by all means. Here is a package pcre
library, for example. Once added, you can use
(?|<(\$)([a-zA-Z0-9]+):([a-zA-Z0-9]+):([a-zA-Z0-9]+)>|{(@)([a-zA-Z0-9 ]+)})
^^^ ^ ^
See the regex demo.