Concept

Custom Character Sets: [abc], [a-z], [^abc]

Square brackets build a custom character class. [abc] matches any of a, b, or c. [a-z] is a range. A leading ^ negates the set.

Basic set syntax

[abc] matches exactly one character: a, b, OR c. The order inside the brackets doesn't matter. Most regex metacharacters lose their special meaning inside a character class — you don't need to escape . or + inside [...].

Ranges

A hyphen between two characters creates a range based on Unicode code points. [a-z] matches any lowercase letter. [A-Fa-f0-9] matches any hex digit. [0-9a-zA-Z_] is equivalent to \w.

Hex digit

Try this
/[0-9a-fA-F]+/

Input

ff5733

Result

Match: ff5733

Vowels

Try this
/[aeiou]/g

Input

regex

Result

Matches: e, e

Negated sets

A caret at the start inverts the set. [^0-9] matches any single non-digit character. [^aeiouAEIOU] matches any consonant or non-letter. Important: the caret is only the negation operator when it's the FIRST character inside the brackets.

Non-digits only

Try this
/[^0-9]+/

Input

abc123def

Result

Match: abc (stops at 1)

Escaping inside brackets

A hyphen is literal at the start or end of a set: [-abc] or [abc-]. A closing ] must be escaped (\]) or placed right after the opening [^. The backslash itself is \\. A caret is literal if it's not first: [a^] matches a or ^.

Related patterns

All reference guidesOpen the RegexPro tester →