Closed sk- closed 9 years ago
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">
Could you add a section to the Readme stating the differences and incompatibilities of re2
compared to ruby's Regexp
.
In plain ruby we have:
whereas in
re2
: