Skip to main content

Verify an AI-generated regex

Use regex101 to verify an AI-generated pattern before putting it into your application.

The integrated AI Assistant can use your existing unit tests and apply reviewed suggestions directly to the editor.

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.

Select the engine used by your application before requesting a pattern. This example uses JavaScript.

Use these cases to define the expected results:

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.

For the integrated assistant, create these unit tests first. Open Attachments and select the cases under Unit tests. For another AI client, include the cases in your request.

Run the pattern in regex101​

  1. In AI Assistant, review the local checks. Then select Apply regex (→) beside the suggested pattern. For another client, paste its pattern into Regular Expression.
  2. Review the flags. This example requires no flags.
  3. Select Unit Tests.
  4. Keep your existing cases. Use Add unit test for any missing rows above.
  5. Set Assertion target to regex.
  6. Set Assertion to does match or does not match, as the row requires.
  7. Open Unit test actions (⋮) and 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. The assistant's results use the tests from when you sent the request. After adding cases, run the applied pattern against them in Unit Tests, or attach them to a follow-up request. 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 Unit test actions > 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.