#match does not return `MatchData` instance in some cases
Closed this issue · 2 comments
BanzaiMan commented
If the regex contains case-insensitive marker, RE2::Regexp#match
returns true
or false
instead.
2.0.0p247 :001 > require 're2'
=> true
2.0.0p247 :002 > re2 = RE2('(?i:abc)')
=> #<RE2::Regexp /(?i:abc)/>
2.0.0p247 :003 > re2.match 'ABC'
=> true
mudge commented
The issue here is that (?flags:re)
is a non-capturing group; as nothing is captured in the expression, the library only returns true
or false
to indicate a match or not.
In contrast:
> RE2('(?i:(abc))').match 'ABC'
=> #<RE2::MatchData "ABC" 1:"ABC">
> RE2('(?i:abc)').match 'ABC'
=> true
I agree that the multiple return types is confusing though and might make the interface more complicated than necessary.
BanzaiMan commented
That makes sense. I guess the workaround is good enough.