--------------enig9A235B2C7DAE61691C0BD2B3
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

benjohn / fysh.org wrote:
> The book I'm reading (o'reilly pocket reference) hints at the look
> arround constructs being:
> 
>   (?=...) - look ahead.
>   (?!...) - negated look ahead.

The following two aren't supported in the current Ruby regexp engine,
they are in the one Ruby 1.9 and on will use.

>   (?<=...) - look behind.
>   (?<!...) - negated look behind.
> 
> So perhaps one of those is what you want?
> 

Either way, it's possible to emulate positive lookbehinds by capturing
what would be the pre-match and putting it into the replacement:

string.sub(/(some lookbehind pattern)(what you're looking for)/) {
  $1 + replacement_of($2)
}

instead of:

string.sub(/(?<=some lookbehind pattern)what you're looking for/) {
  replacement_of($~.to_s)
}

and kludge negative lookbehinds by instead enumerating all the patterns
that would match in a positive one. They just make the pattern
(sometimes much) more elegant in most cases.

David Vallner


--------------enig9A235B2C7DAE61691C0BD2B3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFgGdAy6MhrS8astoRAtncAJ9Uoke+xEbQVwtLYt/oqrVS1eQXGwCdHfUn
oTXyfij7OD5rbcmZu2tAU0Yi
-----END PGP SIGNATURE-----

--------------enig9A235B2C7DAE61691C0BD2B3--