[tpm] Regex question

Indy Singh indy at indigostar.com
Tue Nov 6 10:59:48 PST 2007


That didn't quite work.  The first line is left behind.  Here is the 
result ('foo one' should not be there):

x=foo one
other foo three
more stuff

Indy Singh
IndigoSTAR Software -- www.indigostar.com

----- Original Message ----- 
From: "Mark Fowle" <mfowle at navicominc.com>
To: "Indy Singh" <indy at indigostar.com>; <tpm at to.pm.org>
Sent: Tuesday, November 06, 2007 1:52 PM
Subject: RE: [tpm] Regex question


I think your regex would fail - has four slashes.
I think your solution would fail with foos selarated by another line as
it'll never be at the front.
I changed the expression to \nfoo.*?\n replacing one of the \n
It seems to work as expected.
I'm always scared of regexes being greedy so would probably write

=~s/\n[^\n]*\n/\n/g;

#!/usr/bin/perl
$x='foo one
foo two
other foo three
foo again
more stuff
';
print "x=$x";
#while ($x =~ s/(^|$)foo.*?\n//gs) {1;}
$x =~ s/\nfoo.*?\n/\n/g;
print "x=$x";


-----Original Message-----
From: toronto-pm-bounces+mfowle=navicominc.com at pm.org
[mailto:toronto-pm-bounces+mfowle=navicominc.com at pm.org] On Behalf Of
Indy Singh
Sent: Tuesday, November 06, 2007 1:40 PM
To: tpm at to.pm.org
Subject: [tpm] Regex question

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