AI tools

Free AI regex generator

Describe what you want to match in plain English. Get a regular expression for your language, a token-by-token explanation, and examples that match and don't.

How it works

  1. Describe what you want to match in plain English, and say whether you are checking a whole field or finding matches inside text.
  2. Pick the language or tool you will use it in (JavaScript, Python, Google Sheets and more), paste a few examples if you have them, and click Write my regex.
  3. Get the pattern, a line-by-line explanation, strings that match and don't, and a one-line snippet. Test it on your real data before you ship it.

Examples

Sample results for the inputs shown, so you can see the format and quality before you try it.

Example 1: input

What should the regex match? US phone numbers like (555) 123-4567, 555-123-4567 or 555.123.4567. Validate a form field.

Where will you use it? JavaScript

Example 1: output
Pattern: /^(?:\(\d{3}\) ?|\d{3}[-.])\d{3}[-.]\d{4}$/ Flags: none How it works: ^ ... $ validation: the whole field must be a phone number (?:\(\d{3}\) ?|\d{3}[-.]) area code, either (555) with an optional space, or 555 followed by - or . \d{3} the three-digit exchange [-.] a dash or dot separator \d{4} the last four digits Matches: (555) 123-4567 555-123-4567 555.123.4567 Does not match: 5551234567 (no separators; add them to the pattern if you want to allow this) 555-1234 (missing the area code) (555)-123-4567 (dash after the parentheses) Use it: /^(?:\(\d{3}\) ?|\d{3}[-.])\d{3}[-.]\d{4}$/.test(phone.trim()) Watch out: It also accepts mixed separators such as 555-123.4567. If that matters, capture the first separator and repeat it with a backreference. It does not check that the area code is real, and it rejects +1 prefixes.
Example 2: input

What should the regex match? Pull every order ID out of a log line. Order IDs look like ORD- followed by 8 digits.

Where will you use it? Python

Examples that should and should not match: Match: ORD-00482913 No match: ORD-123, XORD-00482913

Example 2: output
Pattern: \bORD-\d{8}\b Flags: none How it works: \b search, not validation: a word boundary so XORD-... inside a longer word is skipped ORD- the literal prefix \d{8} exactly eight digits \b stops ORD-004829135 (nine digits) from matching its first eight Matches: ORD-00482913 shipped ORD-11223344 today ORD-00000001,ORD-99999999 (both IDs are found) Does not match: ORD-123 (only three digits) XORD-00482913 (the prefix is part of a longer word) ord-00482913 (lowercase; add re.IGNORECASE if your logs vary) Use it: re.findall(r"\bORD-\d{8}\b", line) Watch out: An ID followed by an underscore, such as ORD-00482913_retry, is skipped because _ counts as a word character. Use (?![0-9]) instead of the final \b if those appear.
Example 3: input

What should the regex match? Check whether a cell contains a valid-looking email address

Where will you use it? Google Sheets (REGEXMATCH)

Example 3: output
Pattern: ^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$ Flags: none How it works: ^ ... $ validation: the cell must contain only an email address [A-Za-z0-9._%+-]+ the part before the @ @ the at sign [A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)* the domain, with optional subdomains \.[A-Za-z]{2,} a dot and a top-level domain of two or more letters Matches: [email protected] [email protected] [email protected] Does not match: jane.doe@example (no top-level domain) jane [email protected] (space in the address) @example.com (nothing before the @) Use it: =REGEXMATCH(TRIM(A2), "^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$") Watch out: This checks the shape only. It accepts addresses that look right but don't exist, and a few odd ones like [email protected]. Sheets uses RE2, so the pattern avoids lookaheads on purpose.

Tips for better results

  • Paste real examples of both kinds. "Should match: ORD-00482913. Should not: ORD-123" removes most of the guessing.
  • Say whether you are validating a form field or searching a document. The first needs ^ and $; the second needs word boundaries instead.
  • Pick the right flavor. Google Sheets and Go do not support lookaheads or backreferences, so a pattern copied from a JavaScript answer can fail there.
  • Run the pattern against a sample of your real data in regex101 or your test suite before shipping. The examples on this page are worked by hand, not executed.

FAQ

Is this regex generator free?

Yes. Enter your email once to use it (you'll also get Something Big, our free weekly AI newsletter, and you can unsubscribe anytime). There's no account and no credit card.

Which regex flavors does it support?

JavaScript, Python, PCRE (PHP and grep -P), Java, C# and .NET, Go and Google Sheets (both RE2), and POSIX extended regex for grep -E and sed -E. It writes the pattern and the code snippet for the one you pick.

Is the regex guaranteed to be correct?

No generator can promise that. This one is told to check every example by hand against the pattern and to list the cases it does not handle, but you should still test it on your own data before relying on it.

Can it explain a regex I already have?

Yes. Paste the pattern into the description with "explain and fix this" and it will rewrite it if needed and explain each piece.

More free AI tools

Related prompts

Prefer to use ChatGPT or Claude directly? These free prompts do similar jobs.

Get the best free AI tools and prompts every week

Something Big is a free AI newsletter read by 50,000+ professionals. One email a week with the AI tools and prompts that actually work, plus what changed in AI and what to do about it.