[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] regexp question
- Subject: [ale] regexp question
- From: trobis at speakeasy.net (Taylor Robison)
- Date: Wed Oct 1 13:27:56 2003
- In-reply-to: <000101c38836$e32cc740$f701960a@Vaio01>
- References: <000101c38836$e32cc740$f701960a@Vaio01>
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
>
>