Skip to main content
Regexflux

HTML Tag

intermediate

Matches opening and self-closing HTML tags with optional attributes.

htmltagparsingweb

Pattern

/<([a-zA-Z][a-zA-Z0-9]*)(?:\s+[a-zA-Z-]+(?:="[^"]*")?)*\s*/?>/g

Try It

0 of 6 strings matched

Explanation

Matches an opening HTML tag: < followed by tag name, optional attribute-value pairs, optional self-closing /, and >. Does not match closing tags.

Test Strings

Matching

  • <div>
  • <img src="logo.png" />
  • <input type="text" disabled>

Non-matching

  • </div>
  • < div>
  • <123>

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /<([a-zA-Z][a-zA-Z0-9]*)(?:\s+[a-zA-Z-]+(?:="[^"]*")?)*\s*\/?>/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns