HTML Tag
intermediateMatches opening and self-closing HTML tags with optional attributes.
htmltagparsingweb
Pattern
/<([a-zA-Z][a-zA-Z0-9]*)(?:\s+[a-zA-Z-]+(?:="[^"]*")?)*\s*/?>/gTry 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
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full 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);