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

Named capture cannot be nested inside case-insensitive group #14

Closed BanzaiMan closed 11 years ago

BanzaiMan commented 11 years ago

Compare:

2.0.0p247 :008 > re2 = RE2('(?i:(?<abc>abc))')
re2/re2.cc:197: Error parsing '(?i:(?<abc>abc))': invalid perl operator: (?<
 => #<RE2::Regexp /(?i:(?<abc>abc))/> 

and

2.0.0p247 :009 > re = Regexp.new '(?i:(?<abc>abc))'
 => /(?i:(?<abc>abc))/ 
2.0.0p247 :011 > re.match('abc')
 => #<MatchData "abc" abc:"abc"> 

Not sure if this is supported by re2.

mudge commented 11 years ago

That syntax is not valid for re2: see the official re2 syntax page for full compatibility. Specifically, using (?<name>re) is unsupported; you should use (?P<name>re) instead like so:

> RE2('(?i:(?P<abc>abc))').match('abc')
=> #<RE2::MatchData "abc" 1:"abc">
BanzaiMan commented 11 years ago

Thanks for the explanation.