|
Posted by dan.j.weber on April 9, 2008, 6:25 pm
Please log in for more thread options On Apr 9, 3:18=A0pm, xhos...@gmail.com wrote:
> dan.j.we...@gmail.com wrote:
> > How would I match the text that's after "#ab cd ef#" and before "#qr
> > st uv#" in the following string? I want to use a regular expression
> > that has both a look-behind and a look-ahead together. Is this
> > possible?
>
> > #ab cd ef#gh ij kl#qr st uv#
>
> I don't know what problems you are anticipating, so I'll just try doing it=
> in a straightforward manner:
>
> use strict;
> "#ab cd ef#gh ij kl#qr st uv#" =3D~
> =A0 =A0 /(?<=3D#ab cd ef#)(.*?)(?=3D#qr st uv#)/ or die;
> print $1
> __END__
> gh ij kl
>
> Yep, seems to work. =A0Which is what I expected, because the parts of Perl=
's
> regex language are supposed to work when used together--if they didn't
> there wouldn't be much point in having such a language. =A0Neither look ah=
ead
> nor look behind claim to be an experimental features, so I'd just
> storm ahead and use them with confidence.
>
> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate=
> this fact.
Thanks for your responses. The example I gave was a simplification.
The problem was that I was using (.*) instead of (.*?) and I'm not
100% why, but it doesn't work like that. Thanks.
|