Playing with Oniguruma
I’ve been busy reading Jeffrey Friedl’s Mastering Regular Expressions and getting a little sad that some of the coolest tricks available are not (yet) available in Ruby. Oniguruma, the regular expression engine coming in Ruby 2.0, is more feature-full and faster than what we have now, and makes whole swaths of Mastering Regular Expressions suddenly relevant. I hear it’s possible to recompile 1.8 to use Oniguruma instead, but I’m not quite ready for that.
I am ready for lookbehind and named captures, though. Thankfully, the Oniguruma gem is available to save me from trying to mess up my Ruby install.
The one unsettling thing about using the Oniguruma gem, though, is how they left String’s match method alone. It’s regexp.match(string) only for these things. Thankfully, that’s easily fixed:
class String def o_match(regexp) case regexp when Oniguruma::ORegexp regexp.match(self) else old_match(regexp) end end alias_method :old_match, :match alias_method :match, :o_match end