AI tool · Regex
Regex generator
Describe what to match and get one regular expression, explained part by part, on any of 27 models. Then test it on your own strings with the free tester on this page.
Runs on Plus and Pro, on the model you pick
By running it, you agree to the Terms and Privacy Policy and confirm you’re 18 or older. We keep what you send and its answer for 7 days, or in your account if you sign up.
Test runs checked .
Test a regex on your own strings
Paste any JavaScript regular expression, from the generator or your own code, and one test string per line: each line shows whether it matches and what matched. It runs in your browser and calls no model, so use it as often as you like.
Runs in your browser with its JavaScript regex engine: nothing is sent anywhere, and it's free as often as you like. Python, PCRE and Java differ in a few features, such as lookbehind and possessive quantifiers.
Regex generator: three examples
Three inputs and the regex GPT-6 Luna gave each, made once on September 28, 2026 and shown as it came back. The example buttons in the box above show the same.
A UK postcode such as SW1A 1AA, M1 1AE or B33 8TH, with the space, and nothing else in the string.
```regex
/^(?:GIR 0AA|(?:[A-PR-UWYZ][0-9]{1,2}|[A-PR-UWYZ][A-HK-Y][0-9]{1,2}|[A-PR-UWYZ][0-9][A-HJKPSTUW]|[A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y]) [0-9][ABD-HJLNP-UW-Z]{2})$/i
```
This accepts standard UK postcode formats, including the examples given, plus the special postcode `GIR 0AA`. It is case-insensitive.
- `^` and `$` require the whole string to match.
- `GIR 0AA|...` allows the special postcode `GIR 0AA` or a standard postcode.
- The alternatives before the space describe the permitted outward-code formats.
- The literal space requires a space between the outward and inward codes.
- `[0-9][ABD-HJLNP-UW-Z]{2}` matches the inward code: a digit followed by two permitted letters.
Matches:
- `SW1A 1AA`
- `M1 1AE`
- `B33 8TH`
Does not match:
- `SW1A1AA` (missing space)
- `SW1A 1A` (inward code is too short)
- `SW1A 1AA extra` (extra text)A hex colour code like #fff or #1a2b3c, with the #.
```js
/^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/
```
- `^` and `$` require the entire string to match.
- `#` matches the required hash symbol.
- `(?:...)` groups the allowed colour-code lengths.
- `[0-9A-Fa-f]{3}` matches three hexadecimal digits; `[0-9A-Fa-f]{6}` matches six.
- Hexadecimal digits may be uppercase or lowercase.
Matches: `#fff`, `#1a2b3c`, `#ABC123`
Doesn’t match: `fff`, `#12`, `#12345`Pull the date and the error level out of log lines like: 2026-09-28 14:03:11 ERROR Payment failed.
```regex
^(\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} (ERROR)\b
```
- `^` matches the start of the line.
- `(\d{4}-\d{2}-\d{2})` captures the date as group 1.
- `\d{2}:\d{2}:\d{2}` matches the time.
- `(ERROR)` captures the error level as group 2.
- `\b` ensures `ERROR` ends at a word boundary.
Matches:
- `2026-09-28 14:03:11 ERROR Payment failed.`
- `2024-01-01 00:00:00 ERROR Disk full`
- `1999-12-31 23:59:59 ERROR`
Doesn't match:
- `2026-09-28 14:03:11 WARN Payment failed.`
- `x2026-09-28 14:03:11 ERROR Payment failed.`
- `2026-09-28 ERROR Payment failed.`Which AI model is best at this? We tested every one
In our test runs of 5 Regex generator inputs on 27 models, GPT-6 Luna, GLM 5.3 Flash, Claude Haiku 5.5 and 23 more passed the most: 5 of 5. That includes Claude Haiku 5.5 (an everyday model on every plan).
Run on November 19, 2026: 5 inputs on 27 models, each with this tool's own instructions.
| Model | Passed | Hard ones | Messages used on Pro | Cost per run | Time per run |
|---|---|---|---|---|---|
| GPT-6 LunaOpenAI | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0001 | 14.2 s |
| GLM 5.3 FlashZ.ai | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0002 | 1.7 s |
| Claude Haiku 5.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0003 | 2.8 s |
| DeepSeek V4.1 FlashDeepSeek | 5 of 5 | 2 of 2 | 1 each, of 60 a day on Pro | $0.0008 | 2.4 s |
| Gemini 3.8 FlashGoogle | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0007 | 3.5 s |
| GLM 5.3Z.ai | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0011 | 1.8 s |
| GPT-6.1 TerraOpenAI | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0012 | 7.4 s |
| Mistral Large 4Mistral | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0028 | 14.1 s |
| DeepSeek V4 ProDeepSeek | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0065 | 11.6 s |
| Grok 4.7xAI | 5 of 5 | 2 of 2 | 1 each, of 250 a month on Pro | $0.0079 | 15.9 s |
| GPT-6 SolOpenAI | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0019 | 3.8 s |
| GPT-6.1 SolOpenAI | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0028 | 7.5 s |
| GPT-6.2 SolOpenAI | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0032 | 4.1 s |
| Claude Sonnet 5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0047 | 4.4 s |
| Gemini 4 HydrogenGoogle | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0048 | 7.1 s |
| Kimi K3.1 ProMoonshot | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0048 | 8.2 s |
| Claude Sonnet 5.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0051 | 4.1 s |
| Kimi K3Moonshot | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0052 | 3.5 s |
| Gemini 3.1 Pro (preview)Google | 5 of 5 | 2 of 2 | 1 each, of 125 a month on Pro | $0.0082 | 10.0 s |
| Gemini 4 CarbonGoogle | 5 of 5 | 2 of 2 | 1 each, of 62 a month on Pro | $0.0018 | 5.8 s |
| Gemini 4 ArgonGoogle | 5 of 5 | 2 of 2 | 1 each, of 62 a month on Pro | $0.0019 | 7.0 s |
| Claude Opus 5.5Anthropic | 5 of 5 | 2 of 2 | 1 each, of 62 a month on Pro | $0.0136 | 5.8 s |
| GPT-6.2 AstraOpenAI | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0121 | 4.4 s |
| GPT-6 AstraOpenAI | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0136 | 6.2 s |
| Claude Fable 5.1Anthropic | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0229 | 5.4 s |
| Claude Fable 5.2Anthropic | 5 of 5 | 2 of 2 | 1 each, of 31 a month on Pro | $0.0297 | 7.4 s |
| Claude Haiku 4.5Anthropic | 4 of 5 | 1 of 2 | 1 each, of 250 a month on Pro | $0.0017 | 2.3 s |
Side by side: a password policy
The same input on GPT-6 Luna and Claude Haiku 5.5, as each answered it, unedited.
Write one regular expression for this. Put the pattern alone in a code block first, then explain each part and give strings it matches and doesn't. --- A password with at least 10 characters, at least one uppercase letter, one lowercase letter, one digit and one symbol from !@#$%^&*, and no spaces.
```javascript
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*])[^\s]{10,}$/
```
Assumption: Other non-whitespace characters are allowed; the password must include at least one of the listed symbols.
- `^` and `$` require the entire string to match.
- `(?=.*[A-Z])` requires an uppercase letter.
- `(?=.*[a-z])` requires a lowercase letter.
- `(?=.*\d)` requires a digit.
- `(?=.*[!@#$%^&*])` requires at least one listed symbol.
- `[^\s]{10,}` allows 10 or more non-whitespace characters.
Matches: `Abcdef1!xy`, `Zxcvbn2@pq`, `Aa1234567#`
Doesn't match: `abcdefg1!` (too short), `abcdefgh1!` (no uppercase), `ABCDEFG1!x` (no lowercase)```javascript
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[^\s]{10,}$/
```
Explanation:
- `^` anchors the match to the start of the string.
- `(?=.*[a-z])` is a lookahead requiring at least one lowercase letter somewhere.
- `(?=.*[A-Z])` requires at least one uppercase letter.
- `(?=.*\d)` requires at least one digit.
- `(?=.*[!@#$%^&*])` requires at least one of the listed symbols. Inside a character class, most of these characters are literal, so no escaping is needed.
- `[^\s]{10,}` matches at least 10 characters, none of which is whitespace. This enforces both the length minimum and the no-spaces rule.
- `$` anchors the match to the end of the string.
Assumption: "no spaces" means no whitespace of any kind (spaces, tabs, newlines), and the password may contain characters beyond the listed symbols, such as other punctuation, as long as it meets the other rules.
Strings it matches:
- `Passw0rd!!` (10 characters, all required classes present, no spaces)
- `Tr0ub4dor&3x` (12 characters, all classes present)
- `MyS3cure#Pass` (13 characters, all classes present)
Strings it doesn't match:
- `Passw0rd!` (only 9 characters)
- `password1!` (no uppercase letter)
- `Secure Pass1!` (contains a space)How the inputs are scored
- Test strings: the reply's pattern runs, as JavaScript, on strings it must match and strings it must reject; it passes only if it gets every one right.
The inputs: a us zip code, a hex colour, a 24-hour time, a password policy, and an ipv4 address. Every model gets the tool's own instructions and up to Pro's reply limit. The method is the same as our other test runs.
How to use the Regex generator
Describe what to match, with an example or two of what should and shouldn't. Up to 1,000 characters.
Pick your language's regex flavour.
Press “Write the regex”. It runs on your plan (Plus or Pro) on the model you pick, and the whole answer streams in.
Paste the pattern into the tester below and try it on your own strings, including ones it should reject.
Tips for a better answer
Give a yes and a no
“Matches ORD-2026-00417 but not ORD-26-417” tells the generator more than a paragraph. Give one string that should match and one that shouldn't.
Whole value or search?
Validating a whole field and finding matches inside a longer text need different patterns. Say which one you want.
Try the edges
Test the edge cases: an empty string, extra spaces, lower case, the longest value you expect. That's where patterns break.
Save your test strings
Keep the tester's strings as a comment next to the regex in your code. Next time someone changes it, they can run them again.
What a good regex looks like
It rejects what it should
Try it on strings it should reject, not only ones it should match. Most wrong regexes match too much: an email pattern that accepts “a@b”, a date that accepts month 13.
Anchored when it validates
A pattern that checks a whole value (a postcode, an ID) needs ^ at the start and $ at the end. Without them, “abc12345xyz” passes a five-digit check.
No runaway backtracking
Nested repeats like (a+)+ can take seconds, or forever, on a long string. A good pattern is plain enough that you can read it.
Your language's flavour
JavaScript, Python and PCRE differ in small ways (lookbehind, named groups, flags). The pattern should be in the flavour your code uses.
What you need to run it, and what a run gives
Running it takes a plan, Plus or Pro. There's no free plan or trial: a plan is paid at checkout and renews every month until you cancel. Cancel in two clicks in Settings → Billing and you keep your plan to the end of the month you paid for. llmwise accounts are for people 18 and older.
Paste up to 1,000 characters in a run. It runs on the model you pick, shows the whole answer, and you can carry on in the chat with any model your plan has, or ask another model the same thing.
A run counts on your plan like any other message: the table above shows what one counted as on Pro, model by model.
More AI tools are on the tools page, and what each plan gives is on pricing.
Questions
Is the regex generator free?
No: there's no free plan or trial. It runs on Plus and Pro, on any model your plan has; Claude Fable 5.2, GPT-6.2 Astra, and their earlier versions need Pro. Paid monthly from the day you start. Cancel in two clicks in Settings → Billing. The tester on this page is free and unlimited: it runs in your browser and calls no model.
How do I test the regex?
Paste the pattern into the tester below with its flags, then one test string per line: each line shows whether it matches and what it matched. It uses your browser's JavaScript engine, so it tests JavaScript regexes exactly.
Which regex flavours does it write?
JavaScript, Python, PCRE (PHP) and Java. Pick yours: the pattern and the escaping follow its rules.
Can it explain a regex I already have?
Yes. Paste the regex with a line such as “explain this”, and it breaks it into parts and says what each does.
Which AI writes the most accurate regex?
Our test runs below took each model's pattern and ran it on strings it must match and strings it must reject, and it passed only if it got every one right.
Which AI is best for this, in your tests?
In our test runs of 5 Regex generator inputs on 27 models, GPT-6 Luna, GLM 5.3 Flash, Claude Haiku 5.5 and 23 more passed the most: 5 of 5. That includes Claude Haiku 5.5 (an everyday model on every plan). The table on this page has every model's result, what a run counts as on Pro, and the time it took.
Claude, GPT, Gemini, DeepSeek, Grok, Kimi, GLM, and Mistral, in one chat.
See what a message costs before you send it. Every plan is month to month: cancel in two clicks. Sign in with an email link, no password.