Regex Generator Helper
Build common regex patterns.
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
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?
Why does my custom text match literally?
What do the flags g and i do?
Is my sample text sent anywhere?
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 YouTubeLearn Regular Expressions In 20 Minutes
Web Dev Simplified
Fast path through groups, quantifiers, and character classes.
Watch on YouTube