[tpm] Regex question
Mark Fowle
mfowle at navicominc.com
Tue Nov 6 10:52:35 PST 2007
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