Regex Generator
AI-poweredDescribe what you want to match in plain English and get a JavaScript regex, with a live tester and a token-by-token breakdown.
No pattern yet
01 · Definition
What is a regular expression?
A regular expression (regex) is a pattern that describes a set of strings. Programs use one to find, validate, extract or replace text: \d{4} matches any four digits in a row. JavaScript writes a regex as /pattern/flags, where the flags change how the pattern is applied, such as g to find every match.
02 · Overview
How the Regex Generator works
The generator turns a plain-English description into a JavaScript (ECMAScript) regular expression, with flags and an explanation of each token. The tester is always available and works without the AI: type or paste any pattern, then type, paste or drop a text file to see every match highlighted and counted.
03 · Guide
JavaScript regex flags
A JavaScript regex accepts eight flags, each at most once and in any order. The tester passes the Flags field to new RegExp, so an unknown or repeated flag shows an error under the pattern. It highlights every match whether or not g is set.
The names are the RegExp properties listed in MDN's regular expressions guide. All eight were checked in Node 24, which also rejects u and v used together.
| Flag | Property | Effect |
|---|---|---|
| g | global | Find every match, not only the first |
| i | ignoreCase | Ignore the difference between upper and lower case |
| m | multiline | ^ and $ match at the start and end of each line |
| s | dotAll | . also matches newline characters |
| u | unicode | Read the pattern as Unicode code points; needed for \p{…} |
| v | unicodeSets | u mode with more Unicode features; cannot be combined with u |
| y | sticky | Match only at the current position (lastIndex) |
| d | hasIndices | Record the start and end index of each match and group |
04 · Guide
Regex cheat sheet: common tokens
The tokens below are JavaScript syntax, the flavor this tool generates and tests. Every example was run in Node 24, with the g flag where it lists several matches, and gave the result shown.
| Token | Matches | Example |
|---|---|---|
| \d | A digit, 0 to 9 | \d in a1b22 gives 1, 2, 2 |
| \w | A letter, digit or underscore | \w+ in foo_bar baz-1 gives foo_bar, baz, 1 |
| \s | A space, tab or other whitespace | \s in a b gives the space |
| . | Any character except a newline | With the s flag it matches newlines too |
| [a-c] | One character from the set | [a-c] in abcd gives a, b, c |
| [^a-c] | One character not in the set | [^a-c] in abcd gives d |
| ^ and $ | Start and end of the text | With the m flag, of each line |
| \b | A word boundary | \bcat\b in cat concat cat. gives cat, cat |
| ? + * | 0 or 1, 1 or more, 0 or more of the previous token | a+ in aaa b a gives aaa, a |
| {2,3} | Between 2 and 3 of the previous token | a{2,3} in a aa aaaa gives aa, aaa |
| +? *? | As few as possible (lazy) | a+? in aaa gives a, a, a |
| (…) | A capturing group | (\d+)-(\d+) on 10-20 captures 10 and 20 |
| (?:…) | A group that does not capture | (?:ab)+ in ababab gives ababab |
| a|b | Either side | cat|dog in cat dog cow gives cat, dog |
| (?=…) | Lookahead: followed by | \d+(?=px) in 12px 5em gives 12 |
| (?<=…) | Lookbehind: preceded by | (?<=\$)\d+ in $40 or 40 gives the first 40 |
| \1 | The text captured by group 1 | (a)\1 in aa ab gives aa |
| (?<year>…) | A named capturing group | (?<year>\d{4}) on in 2026 captures 2026 as year |
| \p{L} | A letter in any script (u or v flag) | \p{L}+ in héllo 123 gives héllo |
05 · Use cases
When to use the Regex Generator
- 01
Match all email addresses in a paragraph
- 02
Extract URLs from a log file
- 03
Validate UK postcodes or US ZIP codes
- 04
Find anything that looks like a phone number
- 05
Pull out semantic version strings like v1.2.3
06 · Examples
Regex Generator examples
match all email addresses except gmail
ex 01\b[A-Za-z0-9._%+-]+@(?!gmail\.com)[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b
Matches valid email syntax but uses a negative lookahead to exclude gmail.com.
find UK postcodes
ex 02\b[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}\b
Matches the standard UK postcode format.
match a hex color, with or without #
ex 03#?[0-9a-fA-F]{6}\b
Matches 6-character hex codes with an optional leading #.
extract IPv4 addresses
ex 04\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b
Matches valid IPv4 addresses with bounded octets (0-255).
07 · FAQ
Regex: frequently asked questions
Which flavor of regex does this generate?
How do I use the generated regex in JavaScript?
What do the flags mean?
Why does the explanation not match the regex exactly?
Can I use this for password validation?
Does the test panel save my pasted text?
What happens to the description I type?
08 · Reference
Specs and further reading
These are the primary sources this tool follows. Where a specification defines the behaviour, we link the specification, not a summary of it.
- Regular expressions guide
MDN Web Docs. Reference for JavaScript regex syntax, flags, groups, and lookaround.
- RegExp objects
TC39. The ECMAScript specification text that defines how JavaScript engines evaluate patterns.
- PCRE2 pattern syntax
PCRE. Syntax summary for the PCRE flavour used by PHP and nginx, for checking what differs when you port a JavaScript pattern.
09 · Compare
How this compares to regex101
regex101 is a tester and debugger. It explains a pattern token by token, runs unit tests against it, benchmarks it, and checks it under ten flavour options including PCRE2, Python, Go and .NET. If you are testing or fixing a pattern, use it. The generate.now regex tool drafts a JavaScript-flavour pattern from a plain-English description. Draft here, then test there.
Read the full comparison→10 · More
Tools that pair with Regex
Slug Generator
Convert a title into a URL slug as you type. Choose hyphen or underscore, case and a maximum length; accents become ASCII. One title per line for bulk.
Cron Expression GeneratorAI-powered
Turn plain English into a cron expression, or paste one to get a plain-English reading, a field-by-field breakdown and its next 5 run times.
JSON to TypeScript Types
Paste JSON and get TypeScript interfaces, type aliases, a Zod schema or a Valibot schema. Updates as you type, in your browser.