Regular Expressions 101

Community Patterns

Find all attributes and values of HTML tag

0

Regular Expression
PCRE (PHP <7.3)

/
(\s+)(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?
/
g

Description

This regex will find all attributes, values, and the equal operator, as well as the white space between attributes. You can use this to extract all attributes to remove all inline styles.

Submitted by Demetri Ojeda - 8 years ago