Regex Generator

Build a safe regular expression from curated patterns.

  • Runs locally in your browser
  • No upload required

Try it

Used only for the custom-literal kind; every metacharacter is escaped.

Pattern
^(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})$
Flags
(none)
Notation
/^(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})$/
Linear-time safe
Yes
Matches
dev@example.com
What it matches
Matches a single practical email address (local part, @, dotted domain).

Supported formats

Input
select, text, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Generated the pattern /^(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})$/i.

How it works

  • Selected the curated Email address pattern.
  • Anchored the pattern to the whole string.
  • Composed the flags "i".
  • Verified the pattern has no nested quantifiers, backreferences or lookbehind.
textSelect to copy
^(?:[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})$
  • Curated patterns are reviewed linear-time grammars.
  • The generator does not infer patterns from example text, because inference can produce dangerous backtracking.

Methodology

  1. Select a reviewed pattern from the curated catalogue, or escape the custom literal.
  2. Wrap the pattern in a non-capturing group and add anchors when requested.
  3. Compose the i, g and m flags from the selected options.
  4. Confirm the result contains no nested quantifier, backreference or lookbehind.

Usage

  1. Choose a pattern kind, or custom-literal and enter the literal text.
  2. Choose anchors and flags.
  3. Run the tool, then copy the pattern and flags into your code.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Anchored email

jsonSelect to copy
{
  "kind": "email",
  "literal": "",
  "anchors": true,
  "caseInsensitive": true,
  "global": false,
  "multiline": false
}

Escaped literal

jsonSelect to copy
{
  "kind": "custom-literal",
  "literal": "a.b*c",
  "anchors": true,
  "caseInsensitive": false,
  "global": false,
  "multiline": false
}

Global UUID

jsonSelect to copy
{
  "kind": "uuid",
  "literal": "",
  "anchors": false,
  "caseInsensitive": false,
  "global": true,
  "multiline": false
}

Limitations

Safe by construction

A generator that emits arbitrary patterns can hand you a regular expression that hangs on hostile input. Keeping the catalogue small and reviewed, and escaping custom literals exactly, removes that class of failure.

Frequently asked questions

What is ReDoS?
Regular expression denial of service is caused by patterns that can backtrack exponentially on certain input, such as nested quantifiers. The curated patterns avoid that shape and are reviewed as linear-time.
Why not generate a regex from my sample strings?
Inferring a pattern from examples tends to produce broad, backtracking-prone expressions. This tool favours a small set of reviewed safe patterns and an exact escaped literal instead.

Sources

  1. ECMA-262: ECMAScript Language Specification — RegExp — Ecma International
  2. MDN Web Docs — RegExp — Mozilla
  3. OWASP — Regular expression Denial of Service — OWASP