DevTools Logo

AI Regex Generator

AI Regex Generator

Natural language to regex — on-device WebLLM

Describe the pattern

Examples

Named path segment

Input
Match a GitHub branch name like feature/finetuned-ai-tool-models

Describes shape plus a concrete example — the most reliable phrasing for this model.

Doubled word

Input
Find duplicate words like 'the the' in a sentence

Backreference pattern; verify in Regex Tester — small models often drop the capture group.

ISO date

Input
Match an ISO 8601 date such as 2026-08-21

Fixed-format matching; ask for exact digits, not ranges, for best results.

URL capture

Input
Capture the domain from URLs like https://example.com/path

Asks for a capture group explicitly so the model anchors on the scheme.

About this tool

Natural language to JavaScript regex with link to Regex Tester for validation.

How to use

  1. Describe the pattern

    Say what should match and, ideally, give one or two examples.

  2. Pick a model

    Quality (1.5B) handles anchors and groups more reliably.

  3. Generate

    Get a JavaScript RegExp with a short explanation.

  4. Test it

    Open the linked Regex Tester and check positive and negative cases.

Use cases

Draft without syntax recall

Describe the intent, get a starting pattern instead of re-learning regex syntax.

Form validation

Quick patterns for emails, slugs, dates and other input checks.

Learning by comparison

Compare the generated pattern with your own attempt to spot missed anchors or groups.

Common mistakes

Mistake:Expecting PCRE-only constructs.

Fix:Output targets JavaScript RegExp — recursion and possessive groups do not translate.

Mistake:No negative examples in the prompt.

Fix:Say what should NOT match; otherwise the pattern is often too loose.

Mistake:Nesting quantifiers on long inputs.

Fix:Patterns like (a+)+ on large text can backtrack catastrophically — test with realistic length.

Frequently asked questions

References & standards