Regular Expressions 101

Community Patterns

Remove empty HTML tags

-2

Regular Expression
PCRE (PHP <7.3)

/
<.[^>]*>(\s+|()|(&nbsp;)*|\s+(&nbsp;)*|(&nbsp;)*\s+|\s+(&nbsp;)*\s+)<\/.[^>]*>
/
ig

Description

Removes empty HTML tags. Was needed for old input clean-up and to keep a HTML parses from crashing. Looking for improvement on bottom test.

Submitted by R. Sartorius - 10 years ago