Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
regexp: using (?P<name>re) isn't supported as such #2440
Since none of the regexp functions return a "match object", but rather a slice or slice of slices of actual matches, using a named capture group doesn't actually buy you anything. One easy solution is to just mention in the docs that named captures aren't supported. Another solution might be to have a FindAllStringNamedMatch() function or similar. And another would be to return some kind of "match object" (like Python does with match.group() etc). (I have no preferences/views, merely noting the fact + some ideas.)
I can't see that the new regexp.SubexpNames() method buys much (but perhaps that's my mistake). ISTM that what's needed are something like: regexp.Capture(int) (string, error) regexp.CaptureOf(string) (string, error) which return the index-th or named capture's matching text and nil or an empty string and an error (either no such index/name, or no such match).