Regex Builder
Build a regular expression visually from steps (text, digits, letters, character sets, anchors) with repeats and groups, or start from presets. Live test.
/^\d{3}-\d{4}$/m2 match(es)
What is Regex Builder?
Builds a regular expression from a list of simple steps instead of writing it by hand. Each step is a building block – exact text, digit, letter, word character, whitespace, any character, a character set, an anchor – with a repeat rule and optional group. Ready-made presets (email, URL, IPv4, ISO date, hex color, time, slug, UUID, hashtag, repeated word) give you a starting point, and the generated pattern is tested live on sample text.
How to use Regex Builder
- Pick a preset in Start from a common pattern, or edit the default steps.
- For each step choose the building block, its text or characters, how often it repeats and whether it is a group.
- Use Add step, the arrows and Remove to arrange steps, and tick flags as needed.
- Check the matches in the Test string and copy the Generated pattern.
Example
Steps: start · digit exactly 3 · text "-" · digit exactly 4 · end (flag m)
/^\d{3}-\d{4}$/m – matches 555-1234 and 123-4567, not 55-12345 When to use Regex Builder
Use it when you know what the text looks like but not the regex syntax, or to start from a tested preset. For alternatives (a|b), lookarounds or backreferences, refine the generated pattern in the Regex Tester. The presets are practical patterns, not full RFC validators (for example the email preset does not cover every address the RFC allows).
How Regex Builder works
Each step is translated into regex source: exact text is escaped (so . or ( are matched literally), character sets become […] or [^…] with ], \ and ^ escaped, and blocks map to \d, \w, \s, \p{L}, ., ^, $ or \b. Repeats add ?, *, +, {n}, {n,} or {n,m}; multi-character text is wrapped in a non-capturing group before a quantifier. Capture, non-capture and named groups wrap the step. Steps are concatenated, the u flag is added automatically when \p{L} is used, and the pattern is run against the sample text with the same engine as the Regex Tester.
Common Use Cases
- Creating a pattern for product codes like ABC-1234
- Starting from a preset for dates, emails or UUIDs
- Learning how building blocks map to regex syntax
- Building validation patterns for form fields
FAQs
Can I edit the generated regex by hand?
Copy it into the Regex Tester to refine it. Presets are loaded as an editable pattern fragment.
Why was the u flag added automatically?
The "any letter" block uses \p{L}, which JavaScript only understands in Unicode mode.
Are special characters in my text escaped?
Yes. Exact text steps escape regex metacharacters, so "1.5" matches only "1.5" and not "125".