Regex Character Class Builder ([abc], [a-z], [^...])
Character classes ([abc], [a-z], [^xyz]) are the most flexible regex feature and the easiest to get wrong (especially escaping). This builder lets you check boxes — digits, letters, specific chars, ranges — and outputs the correct character class syntax.
How to use the Regex Character Class Builder ([abc], [a-z], [^...])
Toggle the common classes, add custom chars or ranges, and the regex output updates live. Optional negation wraps the class with ^.
What a character class actually matches
A character class, written with square brackets, matches exactly one character from the set inside it. [aeiou] matches any single vowel, [a-z] uses a range, and [^0-9] negates — matching any one character that is not a digit. Ranges follow code-point order, which is why [A-Za-z] needs two of them: uppercase and lowercase letters are not adjacent in ASCII.
Inside a class the usual rules change. Metacharacters like ., *, and ( become literal, so you almost never escape them here. The few characters that stay special are ], the backslash, ^ (only in first position), and - (only between two characters). To include them literally you put - first or last, or ] first — exactly the placement this builder works out for you.
Common use cases
- Slug and username rules — define precisely which characters an identifier may contain.
- Password policies — build the "at least one of these" sets a strength check needs.
- Input sanitising — strip everything outside an allow-list with a negated class.
- Targeting Unicode ranges — match a specific script or block by code-point range.
- Learning the escaping rules — see why a hyphen or bracket does or does not need a backslash.
Frequently asked questions
Do I need to escape a dot inside <code>[ ]</code>?
*, +, and ? — they lose their special meaning between brackets.How do I include a literal <code>]</code> or <code>-</code> in the set?
] as the very first character, and put - first or last (or escape it as \-). A hyphen between two characters is read as a range, so position is what matters.Why does <code>[a-Z]</code> throw an error?
Z (90) comes before a (97), making it an out-of-order range. Write [A-Za-z] instead, as two valid ranges.Does a negated class like <code>[^a]</code> also match newlines?
[^a] means "any character except a", and that includes line breaks. To exclude newlines too, add them to the class: [^a\n].