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
130 stars 13 forks source link

Expose more of the matching interface in Ruby #119

Closed mudge closed 10 months ago

mudge commented 11 months ago

When I first wrote this gem about a decade(!) ago, I naïvely intended it to be a drop-in replacement for Ruby’s Regexp standard library. However, RE2 not only doesn’t have the same syntax as Ruby’s regular expressions but it has its own unique capabilities that we’re not taking advantage of by hiding it behind a restrictive Ruby API.

Already, RE2::Regexp#match has some poorly documented functionality that is unique to RE2: the ability to specify the exact number of submatches when performing a match which has a significant effect on performance. This should not only be better explained but be a core part of the API along with the other arguments to Match: startpos, endpos (not available on all versions of RE2) and anchor.

This would also create a natural opportunity to introduce the higher-level FullMatch and PartialMatch APIs.

mudge commented 11 months ago

It's also worth nothing that Google's own documentation for RE2 only focusses on FullMatch and PartialMatch and doesn't mention other parts of the API so we should at least offer Ruby analogues.

mudge commented 10 months ago

Version 2.5.0 now exposes the full underlying Match interface upon which the new full_match and partial_match APIs are built.