Regular Expressions 101

Community Patterns

Community Library Entry

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 - 9 years ago