Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: how-to strip empty HTML tags like b /b

( #110566=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > how-to strip empty HTML tags like <b> </b> contributed by Hofmator

I'd also go with tachyon's suggestion of HTML Tidy, but if you are trying to do this quick and dirty somewhere in the middle of a script, I'd use this regex $text =~ s#<\s*([^>]*)\s*>[\s\n]*<\s*/\s*\1\s*>##ig;
It should remove any empty tags which don't contain any attributes (not just bold tags), so it works on

__DATA__ <i> </ I> < B ></b> < em> < / eM >

Comment on Answer: how-to strip empty HTML tags like b /b
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-12-21 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (103 votes), past polls