Skip to content
snip tools

Regex generator

Compose a regex from common presets and refine it against live sample text.

Runs 100% in your browser

 

How to build a regex

  1. Pick a preset or start blank. Use a preset for the common cases (email, URL, hex color, US ZIP, etc.) or build from scratch.
  2. Edit the regex blocks. Type into the pattern field — the matches re-highlight live.
  3. Toggle flags. Set i, g, m, s, u flags as needed. Copy the final regex.

Build it, don't guess it

The hardest part of regex is not the syntax — it's verifying that the pattern accepts everything you intend and rejects what you do not. This tool runs your regex against live sample text the moment you type, so you can see false positives (matches you didn't expect) and false negatives (inputs that should have matched but didn't) immediately. Start from a preset for the common cases; tweak from there. For full debugging — backreferences, groups, look-ahead — pair this page with snip's regex tester.

Start from a battle-tested preset

The presets cover the patterns people reach for most — email, http/https URL, IPv4, hex colour, UUID, US ZIP, ISO 8601 date, 24-hour time, US phone, digits, word characters and URL slugs — each paired with sample text that includes both things it should match and things it shouldn't. They're a deliberately pragmatic starting point, not a promise of perfection: “validate an email with a regex” is famously impossible to do completely, so the email preset accepts the vast majority of real addresses and you tighten or loosen from there against your own examples.

Flags change what the pattern means

The same pattern behaves differently depending on its flags, so they're toggles here: g finds every match rather than just the first, i ignores case, m makes ^ and $ match at each line rather than only the whole string, s lets . match newlines, and u enables full Unicode handling. The copy button emits the pattern in literal /pattern/flags form, ready to paste straight into JavaScript.

Will it work outside JavaScript?

This builds ECMAScript-flavoured regex. The common building blocks — anchors, character classes, groups and quantifiers — behave the same in Python's re, Go's RE2 and PCRE, so most patterns port directly. The edges differ: lookbehind support, some Unicode property escapes, and named-group syntax aren't identical across engines, so always run a generated pattern once in the runtime you'll actually use it in.

Frequently asked questions

How does the regex generator work?
It assembles a JavaScript-flavoured regex from blocks you pick — character classes, quantifiers, anchors, groups — and shows live matches against your sample text. Pick a preset for a head start.
Does it generate regex from natural language?
No — this tool builds regex from explicit, predictable building blocks rather than an LLM. Predictability matters: an LLM-generated regex that "looks right" can quietly mis-validate at scale, where this approach makes every character intentional.
Will the regex work outside JavaScript?
JS regex is ECMAScript-flavoured. Most of what this tool produces (anchors, classes, groups, quantifiers) works the same in Python re, Go regexp (re2) and PCRE — but backreferences inside lookbehinds and some Unicode property escapes differ. Test in your target runtime.
Does my sample text leave the browser?
No. Both the regex and the test text stay in your browser.