Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Extracting Text After <pre> tag in HTML

by graff (Chancellor)
on Sep 22, 2006 at 01:35 UTC ( [id://574286]=note: print w/replies, xml ) Need Help??


in reply to Extracting Text After <pre> tag in HTML

Well, given the sample of data you've shown, this would do what you want (assuming the string is in $_):
s{.*<pre>}{}s;
That is, delete everything up to and including the "pre" tag. Note the "m" modifier at the end, so that "." is allowed to match "\n".

Now, if there's also a  </pre> tag that you're not showing us, and more html data after that, you'll probably want to get rid of that as well:

s{</pre>.*}{}s;
Of course, if a given html page contains more than one "pre" segment, you'll need to be more careful. Ultimately, you might need to actually read the manual page for an HTML parsing module, and start using it, because that would be the preferred approach for this sort of thing.

But if the data are consistently as simple as your sample, a couple regex substitutions will probably suffice.

(updated my regexes to use the "s" modifier as intendedm, rather than the "m" modifier. Thanks, mreece!!)

Replies are listed 'Best First'.
Re^2: Extracting Text After <pre> tag in HTML
by mreece (Friar) on Sep 22, 2006 at 20:13 UTC
    Note the "m" modifier at the end, so that "." is allowed to match "\n".
    you have that backwards! /s allows . to match \n, not /m.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-24 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found