Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by maverick (Curate)
on Jun 28, 2000 at 00:15 UTC ( #20072=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 maverick

you could use =~ in array context like:
$string = "12 34 56 78 90 98 76 54 32 10"; (@matches) = ($string =~ /(\d+)/g); print "fifth match is $matches[4]\n"; print "eigth match is $matches[7]\n";

/\/\averick

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[runrig]: Happy Eclipse Day!

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-08-21 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (325 votes). Check out past polls.

    Notices?