# Regex Inverter

#### by Paul McGuire, January 2026

Description

This page allows you to invert a regular expression, generating strings that match it.

Instructions: Enter a regular expression in the "Regex" field and specify the maximum number of results you want to see (up to 100,000,000). Click "Invert" or press Enter to generate the matching strings.

Constraints:

- Unbounded repetition operators `+` and `*` are not supported.
- Replace `+` or `*` with explicit `{1,n}` or `{min,max}` repetition operators (e.g., use an explicit repetition like `[A-Z]{1,4}` instead of `[A-Z]+`, or `[A-Z]{,4}` instead of `[A-Z]*`).
- For brevity, all generated strings in this utility are limited to 7-bit ASCII characters. By default, Python's `re` methods will match the full Unicode set, so macros like `\d` could match numeric digits in other language character sets beyond just the ASCII digits '0' through '9'.

Note: Complex regular expressions or those with large repetition counts may take some time to process.

Regular Expressions Quick Reference

Construct | Description
--- | ---
`.` | Any character except newline
`\d` | Digit `[0-9]`
`\w` | Word (identifier) character `[a-zA-Z0-9_]`
`\s` | Whitespace character
`\D` | Non-digit
`\W` | Non-word character
`\S` | Non-whitespace character
`?` | 0 or 1 repetition
`{n}` | Exactly n repetitions
`{n,m}` | Between n and m repetitions
`{,m}` | 0 to m repetitions
`[...]` | Character class (any of these characters)
`[^...]` | Negated character class
`|` | Alternation (OR)
`(...)` | Grouping
`(?:...)` | Grouping (non-capturing)
`(?P<name>...)` | Grouping (named group)
Other common regex features not covered in this utility
`^` | Start of a line
`$` | End of a line
`\A` | Start of string
`\Z` | End of string
`*` | 0 or more repetitions (use `{,m}` to limit repetitions)
`+` | 1 or more repetitions (use `{1,m}` to limit repetitions)
`\b` | Word boundary
`(?=...)` | Positive lookahead
`(?!...)` | Negative lookahead
`(?<=...)` | Positive lookbehind
`(?<!...)` | Negative lookbehind

Examples

Here are some example regular expressions to try:

Description | Regex
--- | ---
Match one uppercase letter followed by three digits | `[A-Z]-\d{3}`
Time of day (HH:MM:SS) | `(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])`
8-bit binary numbers | `[01]{8}`
Integer from 0 to 99 | `[1-9]?\d`
Integer from 0 to 255 | `25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d`
Roman Numerals to 50 | `(X{,3}|XL)(I{,3}|IV|VI{,3}|IX)|L`
Chemical Symbol | `A[cglmrstu]|B[aehikr]?|C[adeflmorsu]?|D[bsy]|E[rsu]|F[emr]?|G[ade]|H[efgos]?|I[nr]?|Kr?|L[airu]|M[dgnot]|N[abdeiop]?|Os?|P[abdmortu]?|R[abefghnu]|S[bcegimnr]?|T[abcehilm]|U(u[bhopqst])?|V|W|Xe|Yb?|Z[nr]`
IPv4 addresses in 192.168.0.0/16 | `192\.168(\.((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d))){2}`
MAC address | `[0-9A-Fa-f]{2}([:-][0-9A-Fa-f]{2}){5}`
UUID | `[0-9A-F]{8}(-[0-9A-F]{4}){3}-[0-9A-F]{12}`
Original US Area codes (leading and trailing digit 2-9, middle digit 1 or 0) | `[2-9][10][2-9]`

Enter a regular expression to see its matching strings.

Regex: Max results:

GitHub repo for this page regex-inverter

Powered by PyScript and pyparsing

packages = ["pyparsing"] [[fetch]] files = ["inv_regex.py"]