First off, the regexp package is awesome. I love the new one compared to the old one.
However, it seems that I have to exec a compiled regex twice to get the submatch names and the submatches.
Say I have a regexp like this:
"(?P<lws>\\s*)(?P<token>\\w+)(?P<attrs>\\(([^)])\\))"
This would match any of the following:
" hello(foo='bar', quux='baz')"
"hello(foo='bar', quux='baz')"
"hello"
" hello"
I need to know how much leading white space there is, and the optional attribute list. However, it seems I have do do the following:
n := reg.SubmatchNames(str)
s := reg.FindStringSubmatch(str)
matches := make(map[string]string)
for i, name := range(n[1:]) {
matches[n] = s[i]
}
This type of pattern is pretty common, and I was surprised that there wasn't a call that did both, because other regex engines that allow naming matches have this sort of thing.
For example, in the D programming language:
Is there a reason why this was left out? This would be a really nice feature.
Thanks!