From: David Vallner Date: 2006-12-14T05:49:09+09:00 Subject: Re: Restricted capture in Regexp --------------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: >=20 > (?=3D...) - 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. > (?<=3D...) - look behind. > (?=20 > So perhaps one of those is what you want? >=20 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(/(?<=3Dsome 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 oTXyfij7OD5rbcmZu2tAU0Y= =fLni -----END PGP SIGNATURE----- --------------enig9A235B2C7DAE61691C0BD2B3--