Regex for Semantic HTML5 Tag
Regex Pattern
<\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\s[^>]*)?>HTML5 semantic element tags
Quick Answer
The regex pattern for semantic html5 tag is `<\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\s[^>]*)?>`. HTML5 semantic element tags. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| <header> | ✓ Matches |
| <main class="content"> | ✓ Matches |
| </footer> | ✓ Matches |
| <nav> | ✓ Matches |
| <div> | ✗ No match |
| <span> | ✗ No match |
| <p> | ✗ No match |
| <custom-element> | ✗ No match |
Code Examples
javascript
const regex = /<\\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\s[^>]*)?>/; const isValid = regex.test(value);
python
import re
pattern = r'<\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\s[^>]*)?>'
if re.match(pattern, value):
print("valid")ruby
pattern = /<\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\s[^>]*)?>/ if value =~ pattern puts "valid" end
php
if (preg_match('/<\\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\s[^>]*)?>/', $value)) {
echo "valid";
}java
String pattern = "<\\/?(article|aside|details|figcaption|figure|footer|header|main|mark|nav|section|summary|time)(?:\\s[^>]*)?>"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
HTML Tag
Any HTML tag (opening, closing, or self-closing)
HTML Comment
HTML comment block (multi-line safe)
HTML Attribute
HTML attribute key-value pair (attr="value")
HTML Self-Closing Tag
Self-closing HTML tags like <br/>, <img/>, <input/>
HTML Entity
HTML character entity (named or numeric)
XML Namespace
XML namespace declaration (xmlns or xmlns:prefix)