Regular Expressions 101

Community Patterns

Keep mutliple consective attributes

1

Regular Expression
ECMAScript (JavaScript)

/
<([a-z][a-z0-9]*)(?:[^>]*?((?:\s(?:src|href|style)=['\"][^'\"]*['\"]){0,3}))[^>]*?(\/?)>
/
ig

Description

This regex keeps multiple attributes of given HTML tag. Given that required attributes are consective (in any order) and following the tag name.

Submitted by Ahmad Ahsan - 8 years ago