4 ms·
What's wrong with named capture groups ? http://www.regular-expressions.info/named.html http://www.regular-expressions.info/named.html
by iofj 11y ago
What's wrong with named capture groups ?
http://www.regular-expressions.info/named.html http://www.regular-expressions.info/named.html
- yalue 11y agoThe support for named capture groups in Go's regular expressions is severely lacking, in the sense that it may as well not even exist. There's an API (SubexpNames) that returns an ordered list of the capture group names (if you provided them), but it's up to the user to implement some scheme for mapping a name to the contents of a capture group. At that point, it's probably going to be easier to just use the capture group indices.
- donatj 11y agoI actually use them quite extensively and I don't mind the implementation.
- masklinn 11y agoThey're untyped and inconvenient to put back into a structure: you have to define the struct then a mapping function from regex matches to the struct. This takes care of the mapping through the struct you have to define, and provides somewhat clearer separation of the components (akin to using a VERBOSE flag in some regex engines). Plus not all regex engines support named capture groups, JS's regex don't, and while Go's engine technically supports them it might as well not: you can't index into a match using that, you get a list of group names of size the total number of match groups, and the name at index i is the name of the i'th match group.