mudge / re2

Ruby bindings to RE2, a "fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python".
http://mudge.name/re2/
BSD 3-Clause "New" or "Revised" License
129 stars 13 forks source link

RE2::Regexp.match return is different than Regexp.match #26

Closed sk- closed 9 years ago

sk- commented 9 years ago

In plain ruby we have:

Regexp.new('a').match("a")
 => #<MatchData "a">
Regexp.new('a').match("b")
 => nil

whereas in re2:

RE2::Regexp.new('a').match("a")
 => true
RE2::Regexp.new('a').match("b")
 => false
mudge commented 9 years ago

In retrospect, I think the multiple return types of RE2::Regexp#match are a mistake: it should just consistently return RE2::MatchData objects (even if they contain no captured groups) or nil.

Unfortunately, this would be a breaking API change but we could use a major new version to rethink the API. I'm not sure whether we should be more like Ruby's API or try to match the underlying re2 C++ interface.