HTML Entity
Match HTML entities in named (`&`), numeric (`{`), or hex (`💩`) form.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("&(?:[a-zA-Z][a-zA-Z0-9]+|#\\d+|#x[0-9a-fA-F]+);", "g");
const input = "Tom & Jerry <3";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"&(?:[a-zA-Z][a-zA-Z0-9]+|#\d+|#x[0-9a-fA-F]+);")
input_text = "Tom & Jerry <3"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`&(?:[a-zA-Z][a-zA-Z0-9]+|#\d+|#x[0-9a-fA-F]+);`)
input := `Tom & Jerry <3`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
&(?:[a-zA-Z][a-zA-Z0-9]+|#\d+|#x[0-9a-fA-F]+); (flags: g)Raw source: &(?:[a-zA-Z][a-zA-Z0-9]+|#\d+|#x[0-9a-fA-F]+);
How it works
Examples
Input
Tom & Jerry <3Matches
&<
Input
Numeric:   Hex: 😀Matches
 😀
Input
no entities hereNo match
—Common use cases
- •HTML scraping and entity decoding
- •Email template entity validation
- •Migrating legacy HTML to UTF-8
- •Sanitization pipelines that strip non-ASCII via entities
Related patterns
HTML Attribute
WebMatch HTML attributes of the form name="value" or name='value' and capture both parts.
HTML Comment
WebMatch HTML comments, including multi-line comments and empty ones.
HTML Tag Matcher
WebMatch paired HTML tags and capture the tag name and inner content using a back-reference.
CSS Class from `class=""` Attribute
WebExtract the value of a `class="..."` attribute from raw HTML, handling double or single quotes.