Regular Expressions 101

Community Patterns

Closes properly self-closing tags in HTML

0

Regular Expression
PCRE (PHP <7.3)

~
<([A-z0-9-_]+)(([^>"]+"[^"]*")*\s*)/>
~
gm

Description

In an HTML will replace all auto-closed tags (/>) with a proper tag closing. It works even if the tag has a closing sign (>) inside an attribute.

Submitted by nabab - a year ago