Regex Generator: Build Patterns from Examples

List strings that should match (and some that should not) to infer a pattern, or compose one from tested building blocks. Every example is checked live with your browser’s RegExp engine, each token is explained, and snippets are escaped for JavaScript, Python, PHP, Go, Java and C#. Nothing leaves this page.

Examples

One string per line. In From examples mode these drive the pattern; in Builder mode they are test cases. Up to 200 lines, 500 characters per line, 20,000 characters per box.

No examples yet.

No examples yet.

Make the pattern

Strictness

How the pattern was inferred

    Options

    Flags
    Add examples or parts to generate a pattern.

    Pattern

    You can fine-tune the pattern here. Changing the examples or parts regenerates it and replaces manual edits.

    JavaScript literal and flags

    
        

      Verification

      Nothing to verify yet.

      Token by token

      No pattern to explain yet.

      Code snippets

      Snippets appear once the pattern is valid. Each uses the language’s own string syntax, so backslashes are written exactly as that language needs.

      How it works and limits

      • Inference. Each example is split into runs: digits \d, uppercase [A-Z], lowercase [a-z], spaces or tabs, and each punctuation character as an escaped literal. Examples with the same sequence of run types are aligned column by column and given counts for the chosen strictness. If case-split runs do not align, letters are merged into [A-Za-z]; shapes that still differ become an alternation (?:a|b).
      • Negatives never change the pattern silently. A negative that matches is flagged as FAIL, and the tool suggests the most general strictness level that passes every example, if one exists.
      • A guess, not a specification. The pattern generalises from what you typed and can accept strings you never had in mind. Add near-miss negatives to check it. Letters outside A–Z and other non-ASCII characters are kept as literals.
      • Backtracking guard. The generator and builder never put a repeating quantifier on a group that already contains one. Hand edits are scanned for that shape (for example (a+)+); if found, tests pause until you choose to run them.
      • Blocks. The email block is pragmatic and not RFC 5322 complete. ISO date checks month 01–12 and day 01–31, not month lengths or leap years. IPv4 accepts 0–255 per octet without leading zeros. The slug block allows double hyphens. Semver pre-release and build parts are simplified.
      • Engines. Verification uses this browser’s JavaScript engine. Snippets translate named groups ((?P<name>) for Python and Go) and Unicode escapes, add re.ASCII in Python, add the PHP D modifier and use \z in .NET so $ does not accept a trailing newline. Go (RE2) rejects lookaround and backreferences, and the tool warns when your pattern uses them. Other engine differences are not rewritten.
      • Privacy. Everything runs locally. Nothing is uploaded or stored; reloading the page clears it.