Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: extract substring between token a and token b

by revdiablo (Prior)
on Jul 29, 2004 at 17:02 UTC ( [id://378433]=note: print w/replies, xml ) Need Help??


in reply to extract substring between token a and token b

Your question has been directly answered, but there is a major pitfall to your approach. Even using the non-greedy match, you will run into problems with nested tags. Example:

$input = '<foo>bar<foo>oops</foo></foo>'; print $input =~ m{<foo>(.*?)</foo>}, "\n"; __OUTPUT__ bar<foo>oops

This is one big reason you should avoid simple regular expressions for parsing nested formats, like HTML. The best solution is to use a real parser that actually understands its source data, rather than simple pattern matches.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-03-28 11:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found