Skip to content

Regex Generator

AI-powered

Describe what you want to match in plain English and get a JavaScript regex, with a live tester and a token-by-token breakdown.

Pattern (JavaScript flavour)

No pattern yet

Type a pattern above, or generate one, to see matches highlighted here.

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.

FlagPropertyEffect
gglobalFind every match, not only the first
iignoreCaseIgnore the difference between upper and lower case
mmultiline^ and $ match at the start and end of each line
sdotAll. also matches newline characters
uunicodeRead the pattern as Unicode code points; needed for \p{…}
vunicodeSetsu mode with more Unicode features; cannot be combined with u
ystickyMatch only at the current position (lastIndex)
dhasIndicesRecord the start and end index of each match and group
The eight JavaScript regex flags

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.

TokenMatchesExample
\dA digit, 0 to 9\d in a1b22 gives 1, 2, 2
\wA letter, digit or underscore\w+ in foo_bar baz-1 gives foo_bar, baz, 1
\sA space, tab or other whitespace\s in a b gives the space
.Any character except a newlineWith 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 textWith the m flag, of each line
\bA word boundary\bcat\b in cat concat cat. gives cat, cat
? + *0 or 1, 1 or more, 0 or more of the previous tokena+ in aaa b a gives aaa, a
{2,3}Between 2 and 3 of the previous tokena{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|bEither sidecat|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
\1The 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
Common regex tokens with examples

05 · Use cases

When to use the Regex Generator

  1. 01

    Match all email addresses in a paragraph

  2. 02

    Extract URLs from a log file

  3. 03

    Validate UK postcodes or US ZIP codes

  4. 04

    Find anything that looks like a phone number

  5. 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?

JavaScript (ECMAScript). Our server compiles every generated pattern with JavaScript's RegExp before returning it, and the tester runs it in your browser's engine. Simple patterns often work unchanged in PCRE, Python, Java and .NET, but the engines differ: Go's RE2, for example, has no lookahead, lookbehind or backreferences. Test in the engine you will ship on.

How do I use the generated regex in JavaScript?

Wrap the pattern in slashes with the flags after, for example /pattern/gi, or pass it as a string to new RegExp(pattern, 'gi'). Use String.prototype.match, matchAll, replace, or test depending on what you need.

What do the flags mean?

g matches all occurrences (not just the first), i is case-insensitive, m makes ^ and $ match at line boundaries, s lets . match newlines, u turns on Unicode mode, and y matches only at the current position. The generator picks a small set and you can edit the Flags field. An invalid flag shows an error under the pattern.

Why does the explanation not match the regex exactly?

The token breakdown is written by the AI model for the pattern it generated: character classes, quantifiers and groups, in order. If you edit the pattern afterwards, the page says the breakdown describes the original. If the breakdown is wrong for the original, reword the description; an identical description returns the cached answer for 30 days.

Can I use this for password validation?

You can, but consider whether you need a regex. Most password rules, such as minimum length and character class requirements, are clearer when written as a sequence of small checks. Regex suits extraction and matching better than boolean validation against many rules.

Does the test panel save my pasted text?

No. Matching runs in your browser and the test text is not sent to our server. Only the description you type into the generator is sent.

What happens to the description I type?

The description you type is sent to our server, which passes it to the Anthropic API to produce the result. The result is cached for 30 days under a hash of the description, so the same description returns the same answer. We keep per-IP rate-limit counters: 10 AI generations per hour and 50 per day, shared across the AI tools. Like every page on the site, this one loads page analytics (Vercel Analytics, Speed Insights and aside.so).

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

Last updated .