[tpm] Regex question

Daniel Son dsong at meta-for.org
Tue Nov 6 11:31:50 PST 2007


Sorry, the reply went not to the group, but as personal response. In 
this one:

$x =~ s/^foo.*\n?//gm;

the last ? will ensure that the last line will be matched if there is no 
new line



--
http://www.meta-for.org - Open Source software catalog



Indy Singh wrote:
> Why do I need the last '?' character.  It seems to work without it.
>
> Indy Singh
> IndigoSTAR Software -- www.indigostar.com
>
>
> ----- Original Message ----- From: "Daniel Son" <dsong at meta-for.org>
> To: "Indy Singh" <indy at indigostar.com>
> Sent: Tuesday, November 06, 2007 2:25 PM
> Subject: Re: [tpm] Regex question
>
>
>> Try
>> $x =~ s/^foo.*\n?//gm;
>>
>>
>>
>> -- 
>> http://www.meta-for.org - Open Source software catalog
>>
>>
>>
>> Indy Singh 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
>>>
>


More information about the toronto-pm mailing list