Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Search a match to a regex from the END of a string

by Athanasius (Monsignor)
on Mar 15, 2013 at 12:13 UTC ( #1023677=note: print w/ replies, xml ) Need Help??


in reply to Search a match to a regex from the END of a string

Like this?

22:06 >perl -wE "my $s = 'abc1abc2abc3abc4abc5zz'; $s =~ /.*(abc\d)/; +say qq[matched $1] if $1;" matched abc5 22:07 >

The greedy quantifier in the regex term .* eats up as much of the search string as possible, thereby ensuring that the last match is found.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Search a match to a regex from the END of a string
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023677]
help
Chatterbox?
and the web crawler heard nothing...

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

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls