Regular Expression To Match HTML Tags With Attributes

A Regular Expression to match opening and closing HTML tags with attributes.

/<\/?(\w+)(\s+\w+=(\w+|"[^"]*"|'[^']*'))*>/

Matches:

  • <a>
  • </p>
  • <h1 class=”demo”>

Non-matches:

  • ABC
  • <a
  • <h1 class=”demo”></h1>

See Also:

Regex Is Copied!