Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: Non-greedy regex behaves greedily

by ysth (Canon)
on Jul 28, 2008 at 10:03 UTC ( [id://700491]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Non-greedy regex behaves greedily
in thread Non-greedy regex behaves greedily

You can force the regex engine to start looking for </a> at the end of the string and work forwards by consuming all the string to start with and backtracking character by character:
my $string = q!Back to STATES Menu</font></a></h3> <p align="center">< +a href="index.htm"><img src="home2.gif" alt="Home" border="0" width=" +106" height="30"></a></p> </body> </html>!; if ( $string =~ m!^.*(</a>.*?)$! ) { print "got $1\n"; }
but there's usually a better way to get what you want done.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-29 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found