[thelist] Reg Ex - everything except a phrase
Joshua Olson
joshua at waetech.com
Wed Sep 10 08:56:07 CDT 2003
----- Original Message -----
From: "David Kaufman" <david at gigawatt.com>
Sent: Wednesday, September 10, 2003 9:05 AM
> if, however fred may pop up *multiple* times in the string, notice that
> this simple technique excludes only the *last* fred:
>
> case multifred:
>
> my $d = 'i, not fred, am me, whilst fred is not!';
> $d =~ s/^(.*)(?:fred)(.*)$/$1$2/; print $d, "\n";
>
> prints "i, not fred, am me, whilst is not!",
>
> thanks to greedy matching. if you need to match everything except
> multiple freds, a simple loop is usually best:
>
> $d =~ s/^(.*)(?:fred)(.*)$/$1$2/ while $d =~ /fred/; print $d, "\n";
>
> prints "i, not , am me, whilst is not!"
Dave,
You da man! I'm not familiar with Perl syntax... could you do me a favor
and explain what this line does:
$d =~ s/^(.*)(?:fred)(.*)$/$1$2/ while $d =~ /fred/; print $d, "\n";
Thanks.
<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168
More information about the thelist
mailing list