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

Access to RE2::MatchData via RE2::Scanner #54

Closed lupine closed 1 year ago

lupine commented 3 years ago

Hi,

Today I had occasion to try to replace a usage of the Ruby Regexp class like:

"foo".scan(/(.)/) {|match| ... }

with an RE2 regular expression.

I quickly ran up against the fact that RE2::Scanner#scan returns Array<String> rather than Array<RE2::MatchData>.

In my case, I want access to the begin and end metadata that the RE2::MatchData would carry.

Is this something you'd accept a PR for?

It's possible I'll be able to use ReplaceAll instead, in this particular case, or work around it another way, so I can't guarantee I'll put one together, but I wanted to assess the likelihood of it being accepted early :)

mudge commented 3 years ago

Hi @lupine,

I’d be happy to review a PR for that but we’d need to introduce a new API for it to avoid breaking compatibility. Perhaps another method on Scanner or a separate class altogether?

mudge commented 1 year ago

As there's been no activity on this issue for over a year, I'll close it in a week unless there's an update.