Regex Character Class Builder | Build a JS [...] and test it live
Toggle 8 categories (digits, lower, upper, whitespace, and more) plus custom characters to assemble a JavaScript-compatible character class [...] or [^...]. The pattern runs against your test string with the global flag and highlights every match.
💡 About this tool
A regex character class looks trivial until a stray hyphen turns [a-z] into a range you did not want, or a misplaced ^ flips your whole class into a negation. Inside brackets, -, ^, \ and ] carry special meaning, and the rules about where they are literal versus special are exactly the kind of thing that is easy to forget at 2am while debugging a validation regex.
This builder collects the common categories into checkboxes and lets you drop any extra symbols into one field, escaping ^, -, \ and ] automatically so your class is always valid. The generated pattern runs immediately against the test string and highlights matches, so you can confirm behaviour by eye instead of guessing. Copy the result straight into your source when it looks right.
🧐 Frequently Asked Questions
Q. Will the pattern work outside JavaScript?
A. It follows the JavaScript RegExp syntax. Character-class basics are shared across most engines (PCRE, Python re, Java), so a plain class like [0-9a-z] ports cleanly. Shorthands such as \s can differ between engines, so double-check those when moving the pattern.
Q. How do I include a literal hyphen or other meta character? A. Just type it into the custom characters field. Even in positions that would normally be read as a range, it is escaped automatically and added as a literal.
Q. What is the difference between match and exclude?
A. Match means "any one of these characters"; exclude prepends ^ so the class means "anything except these". Keep the same categories selected and toggle between them to see the contrast.
Q. Is there a size limit on the test string? A. The field itself has no fixed cap, but highlight rendering depends on browser performance, so extremely long input may feel sluggish.
Q. What happens with duplicate characters? A. Characters already covered by a category or another entry are skipped, so the class never bloats with redundant tokens.
📚 Character class quirks worth knowing
Inside a character class, most metacharacters quietly lose their power. A . matches a literal dot rather than "any character", and *, + and ? become ordinary symbols instead of quantifiers. The hyphen is the famous exception: sandwiched between two characters it builds a range, so to use it as a literal you put it at the start or end of the class, or escape it. That asymmetry, where almost everything is defanged but the hyphen and caret still bite, is the single most common reason hand-written classes misbehave, and it is why generating them with automatic escaping saves a lot of head-scratching.