Regex Generator – Build & Test Regular Expressions from Sample Text

Paste sample text to generate an escaped regex, or pick a preset for email, URL, phone numbers, dates, UUIDs and more. Toggle flags, refine the pattern in place, and watch matches highlight live in your test string. Free, private, and runs entirely in your browser.

Build Pattern

Sample text mode
Every regex special character in your sample is escaped automatically, so the pattern matches that text literally. Use Preset above if you want a pattern for a format like email or URL instead.
/(empty)/

Test & Match

Live matching
Matches
0
First at
—
Pattern len
0
Highlighted matches
Match details 0 matches
#IndexMatchGroups

Regex cheatsheet

These are the tokens you'll reach for most often. The generator escapes them for you in Sample text mode, but you'll need them when you edit the pattern or build one by hand.

.Any character except newline (unless the s flag is on).
\dAny digit, equivalent to [0-9].
\wWord character: letters, digits, and underscore.
\sWhitespace: space, tab, newline, carriage return.
\bWord boundary. Useful for matching whole words.
[abc]Any one of the characters inside the brackets.
[^abc]Any character except those inside the brackets.
*Zero or more of the preceding token.
+One or more of the preceding token.
?Zero or one of the preceding token (optional).
{3}Exactly three of the preceding token.
{2,5}Between two and five of the preceding token.
(...)Capture group. Appears in the Groups column of match details.
(?:...)Non-capturing group. Groups without capturing.
|Alternation. Matches either the left or right side.
^Start of string, or start of line with the m flag.
$End of string, or end of line with the m flag.
\Escapes the next character, so it matches literally.

What does this Regex Generator do?

A regex generator turns input into a working regular expression without you having to type the syntax from scratch. This tool has two sources of input. In Sample text mode, whatever you paste is escaped so every special character matches literally — paste 3.14 * 2 and you get 3\.14 \* 2, where the dot and asterisk are no longer wildcards. In Preset mode, you pick a common format like email or URL and the tool loads a ready-made pattern plus a sample test string you can try immediately.

Either way, the result lands in an editable pattern box with a live tester next to it. Every keystroke in the pattern re-runs the match, so you can iterate on an expression and see exactly what it does without switching tabs or reloading a page.

Everything runs locally in your browser. The text you paste never leaves your device, there's no signup, and there are no usage limits.

Literal escaping vs preset patterns

These are two different jobs, and the tool does both:

ModeWhat it doesBest for
Sample textEscapes every regex metacharacter so the pattern matches that exact stringSearching for a specific literal string, log lines, code snippets, or filenames that contain dots or brackets
PresetLoads a structural pattern that matches a category of inputValidating email addresses, extracting URLs, finding dates, phone numbers, UUIDs, or hex colors

The literal mode escapes these characters: . * + ? ( ) [ ] { } ^ $ | \. If you switch on Exact match only, the pattern is wrapped in ^(?:...)$, which forces it to match the entire string rather than a substring somewhere inside it. That's the difference between "contains the text" and "is exactly the text."

Preset patterns are starting points, not final answers. An email preset that works for ada@example.com won't necessarily accept every valid RFC 5322 address, because full email validation is famously more complex than any single regex. Use presets to get 90% of the way, then edit the pattern to tighten or loosen the rules for your specific data.

Understanding the flags

Flags change how the regex engine interprets the pattern without altering the pattern itself. This tool exposes five:

FlagNameEffect
gGlobalFinds all matches in the string, not just the first. Without it, the tester reports one match and stops.
iIgnore caseMakes [a-z] match uppercase too, and vice versa.
mMultiline^ and $ match the start and end of each line rather than the whole string.
sDotall. matches newlines as well as other characters.
uUnicodeEnables full Unicode semantics, including \p{...} property escapes and correct handling of surrogate pairs.

The g flag is on by default so the tester shows every match. The others are off by default because they change matching behavior in ways that can surprise you if you forget they're active.

Reading the match details

Below the highlighted preview, the match details table lists every match the engine found: its index in the test string, the matched text, and any capture groups. Capture groups are the parts of the pattern wrapped in parentheses — for example, (\d{4})-(\d{2}) produces two groups per match, one for the year and one for the month.

If a match is zero-length (a common result of patterns like \b or (?=...) lookaheads), the highlighted preview shows a dashed marker at the match position so you can see where the engine stopped without confusing an empty match with no match at all.

Frequently asked questions

A regex generator builds a regular expression from input you provide — either sample text, which it escapes into a literal pattern, or a preset format like email or URL. It saves you from writing and debugging pattern syntax by hand.
Regex gives special meaning to characters like ., *, +, ?, (, ), [, ], {, }, ^, $, | and backslash. To match them literally, you prefix each with a backslash. For example, the sample text 3.14 becomes the pattern 3\.14 so the dot matches a literal dot instead of any character.
Sample text mode escapes whatever you type so the regex matches exactly that string. Preset mode loads a ready-made pattern for a common format like email, URL, phone number, date, UUID, or hex color, along with a sample test string you can use to verify it.
g (global) finds all matches instead of stopping at the first. i (case-insensitive) ignores letter case. m (multiline) makes ^ and $ match line boundaries rather than the whole string. s (dotall) lets the dot match newlines too. u (unicode) enables full Unicode semantics, including \p{...} property escapes.
Yes. The generated pattern is shown in an editable field. Any change you make is immediately re-tested against the test string, so you can refine the expression without starting over.
The most common causes are missing anchors (so the pattern matches a substring somewhere else), case sensitivity when the i flag is off, or an unescaped special character that's being interpreted as syntax. Check the error banner first — if the pattern is invalid, no match will run at all.
Yes. Enable the m flag to make ^ and $ match the start and end of each line, and the s flag if you want the dot to match newlines as well. The test string preserves newlines, so multi-line inputs work as expected.
Yes. The core pattern syntax is compatible with JavaScript, Python, PHP, Java, Go, and most PCRE-style engines. Note that the flag letters differ by language — Python uses re.IGNORECASE instead of i, for example — so translate the flags when you move the pattern.
Absolutely. Everything runs in your browser. The text you paste never leaves your device — there is no server processing, no logging, and no data storage.
Yes. The tool is fully responsive and works on phones, tablets, and desktops.
Yes. Once the page loads, the generator and tester work without an internet connection. All processing happens locally in your browser using JavaScript.