[ale] regexp question
Taylor Robison
trobis at speakeasy.net
Wed Oct 1 13:27:56 EDT 2003
Perl Cookbook
by Tom Christiansen and Nathan Torkington
O'Reilly
See page 170.
Great book.
#!/usr/bin/perl
$_ = "One fish two fish red fish blue fish";
$WANT = 3;
$count = 0;
while (/(\w+)\s+fish\b/gi) {
if (++$count == $WANT) {
print "The third fish is a $1 one.\n";
# warning: don't 'last' out of this loop
}
}
David Hamm wrote:
> I can?t remember how to replace the nth occurrence of a character in a
> string using a regular expression and I can?t seem to find docs that
> will jog my memory. Could someone help me out?
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale
>
>
More information about the Ale
mailing list