Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How do I find the Nth occurrence of a pattern?

( #68297=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How do I find the Nth occurrence of a pattern? contributed by cLive ;-)

Haven't tested this, but liked the idea.... :)
my $n = whatever... my $i=0; while ( ($string =~ /PATTERN/g) && ($i < $n ) ) { $i++; } my $NthMatch = $1;

Comment on Answer: How do I find the Nth occurrence of a pattern?
Download Code
d'oh
by cLive ;-) (Parson) on Mar 30, 2001 at 10:55 UTC
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-07-28 10:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (195 votes), past polls