Skip to main content
Regexflux

HTML Attribute

intermediate

Extracts attribute name-value pairs from HTML tags.

htmlattributeparsingweb

Pattern

/([a-zA-Z-]+)="([^"]*)"|([a-zA-Z-]+)='([^']*)'|([a-zA-Z-]+)=([^\s>]+)/g

Try It

0 of 7 strings matched

Explanation

Matches HTML attributes in three formats: double-quoted (attr="value"), single-quoted (attr='value'), or unquoted (attr=value).

Test Strings

Matching

  • class="container"
  • id='main'
  • disabled=true
  • data-value="test"

Non-matching

  • = value
  • class
  • "value"

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

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

Related Patterns