Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: keeping one pattern but removing all else from a string

by Cody Pendant (Prior)
on Jul 13, 2002 at 04:07 UTC ( [id://181452]=note: print w/replies, xml ) Need Help??


in reply to keeping one pattern but removing all else from a string

You want to keep all the contents, but remove all tags, except for FONT tags?

I do this the quick and dirty way

Replace all <FONT> tags with a placeholder tag: {{{font}}} for instance.

Then kill all the other tags.

Then put the FONT tags back.

$html =~ s/<($tag[^>]*?)>/{{{$1}}}/sgi;# temp-encode starting tags $html =~ s/<\/($tag[^>]*?)>/{{{\/$1}}}/sgi; # temp-encode ending tags $html =~ s/<[^>]*?>//sgi;# kill all remaining tags $html =~ s/\{{3}/</sgi;# re-encode '<' tags $html =~ s/\}{3}/>/sgi;# re-encode '>'tags

--
($_='jjjuuusssttt annootthheer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;

Replies are listed 'Best First'.
Re: Re: keeping one pattern but removing all else from a string
by Anonymous Monk on Jul 15, 2002 at 04:48 UTC
    Thank you. The solution by Cody Pendant above is what i was looking for and it worked fine as I wanted.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found