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:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.