Webflags: g
HTML Attribute
Match HTML attributes of the form name="value" or name='value' and capture both parts.
Try it in RegexProPattern
regexJavaScript
/\b([a-zA-Z][a-zA-Z0-9\-]*)=["']([^"']*)["']/gRaw source: \b([a-zA-Z][a-zA-Z0-9\-]*)=["']([^"']*)["']
How it works
Group 1 captures the attribute name (letters, digits, hyphen). Group 2 captures the quoted value. Matches both double and single quoted forms.
Examples
Input
<a href="https://x.com">Matches
href="https://x.com"
Input
<img alt='logo' src='/a.png'>Matches
alt='logo'src='/a.png'
Input
<div></div>No match
—Common use cases
- HTML template parsing
- Attribute extraction for SEO audits
- Accessibility linting (alt, aria-*)
- Static analysis of template files