Regex Generator Helper

Build common regex patterns.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Choose what you want to match and this tool writes the regular expression for you, then explains each part in plain English. Pick between finding matches inside text and checking that a whole string is valid, toggle case-insensitive and global, and test the pattern against your own sample text with every match highlighted. Copy it as a /regex/ literal or a new RegExp() call.

How to use

1
Step 1
Pick a pattern type from the list, or choose Custom text and type the characters to match.
2
Step 2
Choose whether to find matches inside text or require the whole string to match, and set the ignore-case and find-all options.
3
Step 3
Read the explanation, try the pattern on the sample text, and copy the regex.

How it works

Each preset is a hand-written JavaScript pattern. In find mode, patterns that start and end with letters or digits get \b word boundaries so a match is not cut out of a longer word or number. In whole-string mode the pattern is wrapped in ^(?:...)$ so nothing else may appear, which is what you want for form validation. Custom text is escaped, so characters like. ( + ? match themselves. The highlighted test runs the same regex in your browser on your sample.

Worked example

IPv4 addresses inside text

Input
Type: IPv4 address, find matches inside text, find all
Output
/\b(?<!\d\.)(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?!\.\d)\b/g
Walkthrough
Each octet is limited to 0-255, three octets end with a dot, and a fourth follows. Tested on '8.8.8.8 256.1.1.1 10.0.0.255' it matches 8.8.8.8 and 10.0.0.255 but not 256.1.1.1.

Limitations

  • The presets are practical, not exhaustive: the email pattern is not a full RFC 5322 validator and the phone patterns cover common US and international layouts, not every national format.
  • Date presets check the shape (month 01-12, day 01-31) but not whether the day exists, so 02/31/2026 still matches.
  • The IPv4 and whole-number presets use a lookbehind, (?<!\d\.), so they skip pieces of longer dotted numbers like 1.2.3.4.5. Lookbehind needs Chrome, Firefox, Edge or Safari 16.4 and later.
  • Output is JavaScript regex syntax; other engines (PCRE, Python, Java) are mostly compatible for these patterns but check named groups and flags.
  • To test a pattern you wrote yourself, use the Regex Tester.

Questions

What is the difference between find and whole string?
Find mode locates matches anywhere in a longer text. Whole-string mode adds ^ and $ so the entire input must be one valid value, which is how you validate a form field.
Why does my custom text match literally?
Characters such as. * + ? ( ) are escaped automatically, so typing a.b matches the three characters a.b and not a, any character, then b.
What do the flags g and i do?
g finds every match instead of only the first. i ignores upper and lower case.
Is my sample text sent anywhere?
No. The pattern is built and tested in your browser.

Features

  • 14 ready-made patterns plus custom text
  • Plain-English explanation
  • Highlighted live tester
  • Whole-string or find mode
  • Copy as /regex/ or new RegExp()

Guides

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Learn Regular Expressions (Regex) - Crash Course

    freeCodeCamp.org

    Full regex primer for tester and explainer tools.

    Watch on YouTube
  • Learn Regular Expressions In 20 Minutes

    Web Dev Simplified

    Fast path through groups, quantifiers, and character classes.

    Watch on YouTube
  • RegExp

    MDN

    Flags and methods reference when a pattern behaves unexpectedly.

  • Base64

    MDN

    When Base64 is appropriate versus raw binary transfer.