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.