Different behavior for '^'
Closed this issue · 2 comments
sk- commented
In plain ruby we have:
Regexp.new('^a').match("\na")
=> #<MatchData "a">
whereas in re2
:
RE2::Regexp.new('^a').match("\na")
=> false
mudge commented
This is due to a difference in the underlying Google re2 library's syntax which isn't 100% compatible with PCRE: in order for ^
to match the beginning of a line, you need to use the multi-line mode flag.
RE2::Regexp.new('(?m)^a').match("\na")
=> true
Or, using a capturing group to return the match:
RE2::Regexp.new('(?m)(^a)').match("\na")
=> #<RE2::MatchData "a" 1:"a">
sk- commented
Could you add a section to the Readme stating the differences and incompatibilities of re2
compared to ruby's Regexp
.