DD
DevDash

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

InputResult
<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

Want API access + no ads? Pro coming soon.