JavaScript Regex Generator
Pick what you need to match, or assemble a pattern from plain-language parts, and get a working JavaScript regular expression with an explanation, a live test and code to paste. Each ready-made pattern states honestly what it does not check.
- Private by default
- No sign-up
- Free to use
Pattern
Test result
How to use JavaScript Regex Generator
- Choose a ready-made pattern, or “Custom” to build one from parts.
- Select whether you want to validate a whole value or find matches inside text.
- Check the result against the test text and add your own examples.
- Copy the pattern, or the JavaScript snippet that uses it.
JavaScript Regex Generator features
Pattern library
Email, URL, domain, IP address, dates, time, numbers, colours, UUID, version numbers, postcodes and more.
Builder in plain words
Combine parts such as “exactly 2 letters”, “the text -” and “4 digits” without writing regex syntax.
Validate or find
Adds anchors for validation, or word boundaries and the g flag for searching, as appropriate.
Live test
Each test line shows match or no match; in find mode, matches are highlighted in the text.
Explained
Every pattern comes with a description and its known limits, so you know what it will let through.
Code included
A JavaScript snippet with test(), match(), matchAll() and replace(), plus the new RegExp string form.
When to use JavaScript Regex Generator
- Adding format checks to a form field.
- Extracting dates, links or numbers from a block of text.
- Building a pattern for a custom product code or reference number.
- Learning regular expressions by seeing how plain rules translate into syntax.
JavaScript Regex Generator FAQ
How is this different from the Regex Tester?
The tester is for a pattern you already have: you type the expression and inspect matches and groups. The generator starts earlier, from the thing you want to match, and writes the expression for you. The two work well together.
Is the email pattern a complete validation?
No, and no regular expression is. It checks that the text has the shape of an address. Whether the mailbox exists can only be confirmed by sending a message to it. The pattern also rejects some rare forms that the standard allows, which is the usual practical trade-off.
What do ^ and $ do?
They anchor the pattern to the start and end of the value. Without them, a pattern for five digits would also accept “abc12345xyz”, because five digits occur somewhere inside. For validation you nearly always want both anchors.
Why does test() give alternating results with the g flag?
A global regular expression object remembers where its last match ended in its lastIndex property, and the next test() continues from there. For yes-or-no checks use a pattern without g, which is what the generated validation code does.
Why are backslashes doubled in new RegExp?
Inside a JavaScript string, a backslash is itself an escape character, so \d has to be written as "\\d". In a regex literal between slashes a single backslash is enough. The snippet shows both forms.
Can I use these patterns in other languages?
Mostly. The syntax used here is common to JavaScript, PHP (PCRE), Python and Java. The literal form with slashes and flags is JavaScript-specific, and the hashtag pattern relies on Unicode property escapes, which need the u flag in JavaScript.
Writing regular expressions that do what you mean
A regular expression describes a set of strings. Most of the difficulty is being exact about which set you mean. “A date” might be any four digits, a dash, two digits, a dash and two digits, or it might require the month to be between 01 and 12. Each added rule makes the pattern longer and stricter. The ready-made patterns here take a practical middle position and say where they stop: the date pattern knows the range of months and days, but not that February has no 31st.
Two decisions matter as much as the pattern itself. The first is anchoring. A pattern used for validation must match the whole value, which the ^ and $ anchors enforce. A pattern used for searching must not be anchored, and usually needs boundaries so that it does not match inside a longer word or number. The second is flags: g to find every occurrence, i to ignore case, m to make the anchors work per line, u for full Unicode. The generator sets these according to how you intend to use the pattern.
The builder shows how patterns are composed. Each part is an atom, such as a literal text, a character class like \d, or a set in square brackets, followed by a quantifier that says how many times it may repeat. Literal text is escaped automatically, so a dot or a plus sign in your text is matched as that character and not interpreted as syntax. Reading the generated expression next to the plain-language list of parts is a quick way to learn the notation.
A word of caution about relying on patterns for security or correctness. Regular expressions are good at checking shape and bad at checking meaning. A card number needs a checksum, a date needs a calendar, an address needs a delivery attempt. Use the pattern as a first filter that gives users quick feedback, and let the server apply the real rules. And always test with examples that should fail as well as examples that should pass.