Skip to content

Free tool · Regex

Regex generator

Describe what to match and get one regular expression, explained part by part, in 1 free run a day on GPT-6 Luna, no account needed. Then test it on your own strings with the free tester on this page.

1 free run a day, no account needed

GPT-6 Luna

Up to 1,000 characters. No files, tools or web search in a free run. One free run a browser, and one a network each day, shared with the free message on our home page.

Try an example:

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 . Updated .

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 a free run gave each, made once on September 28, 2026 with GPT-6 Luna and shown as it came back. The example buttons in the box above show the same.

A UK postcode

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

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`
Parts of a log line

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

Every one of the 16 models we ran passed all 5 of our Regex generator test inputs, so choose on speed and price: GLM 5.3 was quickest, at 1.4 s a run on average. GPT-6 Luna, the model a free run is on, took 3.7 s.

Run on September 28, 2026: 5 inputs on 16 models, each with this tool's own instructions.

Each model's results on the tool's test inputs
ModelPassedHard onesMessages used on ProCost per runTime per run
GPT-6 LunaOpenAIThe free run's model5 of 52 of 21 each, of 60 a day on Pro$0.00013.7 s
GLM 5.3 FlashZ.ai5 of 52 of 21 each, of 60 a day on Pro$0.00029.6 s
DeepSeek V4.1 FlashDeepSeek5 of 52 of 21 each, of 60 a day on Pro$0.00084.8 s
Gemini 3.8 FlashGoogle5 of 52 of 21 each, of 250 a month on Pro$0.00062.1 s
GLM 5.3Z.ai5 of 52 of 21 each, of 250 a month on Pro$0.00131.4 s
Claude Haiku 4.5Anthropic5 of 52 of 21 each, of 250 a month on Pro$0.00172.9 s
DeepSeek V4 ProDeepSeek5 of 52 of 21 each, of 250 a month on Pro$0.004610.9 s
Grok 4.7xAI5 of 52 of 21 each, of 250 a month on Pro$0.005210.2 s
GPT-6 SolOpenAI5 of 52 of 21 each, of 125 a month on Pro$0.00244.4 s
Kimi K3Moonshot5 of 52 of 21 each, of 125 a month on Pro$0.00327.4 s
Claude Sonnet 5Anthropic5 of 52 of 21 each, of 125 a month on Pro$0.00494.7 s
Claude Sonnet 5.5Anthropic5 of 52 of 21 each, of 125 a month on Pro$0.00503.2 s
Gemini 3.1 Pro (preview)Google5 of 52 of 21 each, of 125 a month on Pro$0.00739.9 s
Claude Opus 5.5Anthropic5 of 52 of 21 each, of 62 a month on Pro$0.01416.6 s
GPT-6 AstraOpenAI5 of 52 of 21 each, of 31 a month on Pro$0.014036.2 s
Claude Fable 5.1Anthropic5 of 52 of 21 each, of 31 a month on Pro$0.02295.0 s
Passed: of the 5 test inputs, how many answers passed their check (an answer the provider failed to give isn't counted). Messages used: what each run counted as on Pro, and Pro's count on the model. Cost: what OpenRouter charged us per run, on average; in llmwise you pay per message, not per token. Time: from sending to the whole answer.

Side by side: a password policy

The same input on GPT-6 Luna and GLM 5.3 Flash, 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.
GPT-6 Luna
```regex
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*])\S{10,}$/
```

Assumption: “no spaces” means no whitespace characters, including tabs and line breaks.

- `^` and `$` require the entire password to match.
- Each `(?=...)` lookahead requires at least one uppercase letter, lowercase letter, digit, and permitted symbol.
- `\S{10,}` requires at least 10 non-whitespace characters.

Matches: `Abcdefg1!x`, `PassWord9#z`, `A1!bcdefghij`

Doesn’t match: `abcdefghi1!` (no uppercase), `ABCDEFGHI1!` (no lowercase), `Abcdefghi1` (no permitted symbol)
GLM 5.3 Flash
Assumption: the whole string must be exactly the password — no leading/trailing spaces either, since no spaces are allowed anywhere.

```javascript
/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*])\S{10,}$/
```

- `^` and `$` — match the whole string, not just part of it.
- `(?=.*[A-Z])` — lookahead requiring at least one uppercase letter.
- `(?=.*[a-z])` — lookahead requiring at least one lowercase letter.
- `(?=.*\d)` — lookahead requiring at least one digit.
- `(?=.*[!@#$%^&*])` — lookahead requiring at least one of the allowed symbols.
- `\S{10,}` — 10 or more non-whitespace characters, which also enforces the "no spaces" rule.

Matches:
- `Abcdef1!xyz`
- `Passw0rd!Long`
- `Xy9#aaabbbccc`

Doesn't match:
- `abcdef1!xyz` (no uppercase)
- `Abcdef1xyzAB` (no symbol)
- `Abc de1!xyz` (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

  1. Describe what to match, with an example or two of what should and shouldn't. Up to 1,000 characters.

  2. Pick your language's regex flavour.

  3. Press “Write the regex”. Without an account you see the start (1 free run a day, no account needed).

  4. 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's free, and what signing up adds

  • Without an account: 1 free run a day, on GPT-6 Luna, shared with the free message on our home page. It takes up to 1,000 characters, writes up to about 600 tokens (roughly 450 words), and shows you the start of the regex.

  • Signing up is free, with an email link and no card. llmwise accounts are for people 18 and older. The regex you ran comes with you as your first chat, and you get 5 free messages on almost every model (all but Claude Fable 5.1, Claude Opus 5.5, and GPT-6 Astra).

  • Signed in, the tool runs on the model you pick, on your plan, shows the whole answer, and you can carry on in the chat with any model, or ask another model the same thing.

More free tools are on the tools page, and what each plan gives is on pricing.

Questions

Is the regex generator free?

Yes. Without an account you get 1 run a day on GPT-6 Luna, shared with the free message on our home page: you see the start of the answer, and the rest when you sign up. The tester on this page is free and unlimited: it runs in your browser and calls no model. Signing up is free and adds 5 free messages on almost every model in llmwise (all but Claude Fable 5.1, Claude Opus 5.5, and GPT-6 Astra), with no card.

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?

Every one of the 16 models we ran passed all 5 of our Regex generator test inputs, so choose on speed and price: GLM 5.3 was quickest, at 1.4 s a run on average. GPT-6 Luna, the model a free run is on, took 3.7 s. 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, and GLM, in one chat.

See what a message costs before you send it. Free is 5 messages to try; sign in with an email link, no password or card.