Skip to main content

Verify an AI-generated regex

Use regex101 to verify an AI-generated pattern before putting it into your application. Matching and unit tests run locally in your browser and are included in Free.

Define the expected result​

This example accepts a complete order identifier: ORD- followed by exactly four ASCII digits. It rejects extra characters, lowercase prefixes, and empty input.

Give your AI client the requirement and these cases:

InputExpected result
ORD-0042Match
ORD-9999Match
ORD-42No match
ORD-00000No match
XORD-0042No match
ord-0042No match
Empty inputNo match
ORD-0042 followed by a newlineNo match

Specify the target language and whether the pattern searches within text or must match the entire input. When you use an AI service, choose synthetic examples. Your AI client controls how it handles conversation content.

Run the pattern in regex101​

  1. Select the engine used by your application. This example uses JavaScript.
  2. Paste the returned pattern into Regular Expression.
  3. Set the flags the client supplied. This example requires no flags.
  4. Select Unit Tests.
  5. Use Add unit test for each row above.
  6. Set Assertion target to regex.
  7. Set Assertion to does match or does not match, as the row requires.
  8. Select Run tests.

For this requirement, the following pattern passes the listed cases:

^ORD-[0-9]{4}$

Open in regex101

Compare this example with your generated pattern. If a case fails, keep that case and refine the pattern against it. Add cases you chose independently of the AI response. Passing these tests proves the listed expectations, not every possible input.

For extracted values, also compare captured text.

Verify the application behavior​

  1. Select Match mode.
  2. Open Code Generator.
  3. Choose your target language.
  4. Run the code in your application's runtime with each case above.
  5. Compare the engine version, flags, matching operation, and input characters.
  6. Save a versioned workspace to keep the pattern and unit tests together.

Runtime troubleshooting covers escaping, HTML forms, and differences between search and whole-input validation.

Use MCP to prepare a workspace​

New workspaces created by MCP are public. For private content, use the private browser save mode or Workspace API.

  1. Choose the MCP setup instructions for your client.
  2. Ask the client to save the pattern and unit-test definitions.
  3. Open the returned workspace link.
  4. Select Unit Tests.
  5. Select Run tests to evaluate the expectations locally.

MCP does not execute matches or run unit tests. A regex explanation also does not establish that the pattern meets your requirements.