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 modeTest & Match
Live matching| # | Index | Match | Groups |
|---|
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:
| Mode | What it does | Best for |
|---|---|---|
| Sample text | Escapes every regex metacharacter so the pattern matches that exact string | Searching for a specific literal string, log lines, code snippets, or filenames that contain dots or brackets |
| Preset | Loads a structural pattern that matches a category of input | Validating 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:
| Flag | Name | Effect |
|---|---|---|
g | Global | Finds all matches in the string, not just the first. Without it, the tester reports one match and stops. |
i | Ignore case | Makes [a-z] match uppercase too, and vice versa. |
m | Multiline | ^ and $ match the start and end of each line rather than the whole string. |
s | Dotall | . matches newlines as well as other characters. |
u | Unicode | Enables 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
., *, +, ?, (, ), [, ], {, }, ^, $, | 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.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.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.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.re.IGNORECASE instead of i, for example — so translate the flags when you move the pattern.