[tpm] Regex question
Indy Singh
indy at indigostar.com
Tue Nov 6 11:21:10 PST 2007
> $x =~ s/(^|$)foo.*?\n//mgs;
Your use of the 'm' option suggested a cleaner solution:
$x =~ s/^foo.*?\n//mg;
The '$' and the 's' option are not needed.
Thanks.
Indy Singh
IndigoSTAR Software -- www.indigostar.com
----- Original Message -----
From: "Emil Janev" <ejanev at gmail.com>
To: <tpm at to.pm.org>
Cc: "Indy Singh" <indy at indigostar.com>
Sent: Tuesday, November 06, 2007 1:55 PM
Subject: Re: [tpm] Regex question
> Hi Indy,
>
> Instead of:
>
> while ($x =~ s//(^|$)foo.*?\n//gs) {1;}
>
> I tried:
>
> $x =~ s/(^|$)foo.*?\n//mgs;
>
> and it gives the same result.
>
> Regards,
> Emil
>
> On Nov 6, 2007 1:39 PM, Indy Singh <indy at indigostar.com> wrote:
>> Hello all,
>>
>> I have some multiline data as shown below. I want to remove all
>> occurances of 'foo.*?' that are at the beginning of a line. How can
>> I
>> do that witha regex. I can do it with a while loop, but is a there a
>> more elegent way with a single regex? Perhaps using some look ahead
>> or
>> look behind assertion.
>>
>>
>> $x='foo one
>> foo two
>> other foo three
>> more stuff
>> ';
>> print "x=$x";
>> while ($x =~ s//(^|$)foo.*?\n//gs) {1;}
>> print "x=$x";
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/toronto-pm
>
>
> --
> Emil Janev
More information about the toronto-pm
mailing list