Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by cLive ;-) (Prior)
on Mar 30, 2001 at 10:53 UTC ( #68297=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I find the Nth occurrence of a pattern? - Answer 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;

Replies are listed 'Best First'.
d'oh
by cLive ;-) (Prior) on Mar 30, 2001 at 10:55 UTC
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-03-30 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (356 votes). Check out past polls.