re2

Installation

You will need re2 installed as well as a C++ compiler such as gcc (on
Debian and Ubuntu, this is provided by the build-essential package). If
you are using Mac OS X, I recommend installing re2 with Homebrew by
running the following:

$ brew install re2

If you are using Debian, you can install the libre2-dev package like so:

$ sudo apt-get install libre2-dev

Recent versions of re2 require a compiler with C++11 support such as clang 3.4 or gcc 4.8.

If you are using a packaged Ruby distribution, make sure you also have the
Ruby header files installed such as those provided by the ruby-dev package
on Debian and Ubuntu.

You can then install the library via RubyGems with gem install re2 or gem
install re2 -- --with-re2-dir=/opt/local/re2 if re2 is not installed in the
default location of /usr/local/.

As of 0.6.0, you can use RE2::Regexp#scan to incrementally scan text for
matches (similar in purpose to Ruby's
String#scan).
Calling scan will return an RE2::Scanner which is
enumerable meaning you can
use each to iterate through the matches (and even use
Enumerator::Lazy):