nitely / nim-regex

Pure Nim regex engine. Guarantees linear time matching
https://nitely.github.io/nim-regex/
MIT License
227 stars 20 forks source link

Allow or forbid duplicated group names #53

Open nitely opened 4 years ago

nitely commented 4 years ago

The following code compiles, but the group just contains the last capture:

var m: RegexMatch
doAssert "abab".match(re"(?P<foo>ab)(?P<foo>ab)", m)
doAssert m.group("foo") == @[2 .. 3]
doAssert m.group(0) == @[0 .. 1]
doAssert m.group(1) == @[2 .. 3]

So, we can either throw a compile error, same as PCRE, or we can make foo return both group captures. The latter sounds like a nice feature for expressions like "(?P<foo>ab)|(?P<foo>cd)|(?P<foo>ef)".