Guide

Test a Regex with Sample Text

Enter a nonempty regex pattern and sample text, choose a recognized matching mode when needed, and start the evaluation. A successful result shows the match total and can include positions, matched text, and capture groups.

Tool Regex Tester

When a regex tester is useful

A regex tester helps you check a regular-expression pattern against sample text and see what the pattern finds. It is useful when you need more than a pass-or-fail impression, because a successful evaluation can show the number of matches, each match's positions, the matched text, and captured groups.

Steps for checking a pattern

  1. Enter the pattern you want to examine. For example, \bcat\b looks for cat as a separate word rather than the same letters inside a longer word.
  2. Enter sample content in the test-text field. Use text that represents the cases you want to check, including examples that should match and nearby text that should not.
  3. Add flags only when they suit the pattern. The recognized choices are i for case-insensitive matching, m for multiline matching, s for dot-all matching, x for verbose matching, u for Unicode matching, and a for ASCII matching. Characters outside this set do not activate a matching mode.
  4. Start the evaluation with the available action control.
  5. Read the returned status and match information before changing the pattern. A valid evaluation may report no matches, which is a useful result when the sample does not contain the requested form.

The pattern, test text, and flags are optional text inputs and begin as empty strings. That does not make every empty combination evaluable: an empty pattern fails before matching, and empty test text fails when a pattern has been supplied. A pattern that cannot be compiled also causes the evaluation to fail, so correct its regular-expression syntax before relying on the details.

Understanding the evaluation

A successful result is marked as valid and includes the total number of matches. When matches exist, inspect the start and end positions alongside the text captured by each match. Capture groups can add numbered groups and named groups, allowing you to check the portions selected by parentheses in the pattern.

A valid total of zero means the pattern was evaluated but did not find a match in the supplied text. Treat that outcome differently from a failure, because failure means evaluation could not proceed. Empty input, an uncompileable pattern, or a pattern paired with empty test text can prevent match details from being returned. Review the flags as well: an unsupported character is ignored rather than activating an additional matching mode.

After reading the result, adjust one input at a time and evaluate again. This makes it easier to tell whether a change to the pattern, sample text, or recognized flag caused the difference.

Worked example

You want to check whether a word-boundary pattern finds separate occurrences of cat without treating those letters inside catalog as a match.

Enter \bcat\b, add cat catalog cat as the sample text, leave the flags empty, and start the evaluation.

The successful result is marked valid and reports a match total of 2. The first match is cat at positions 0 to 3, and the second match is cat at positions 12 to 15; the letters inside catalog are not matched. The pattern has no capture groups, so none are listed.

Limitations

  • Match details are unavailable when the pattern is empty, when supplied test text is empty, or when the pattern cannot be compiled.

Common errors

  • If evaluation fails because the pattern is empty or cannot be compiled, enter a nonempty pattern and correct its regular-expression syntax before checking the match details.

FAQ

How do I test a regex against text?

When the pattern is valid and the test text is nonempty, start the evaluation to receive a match total and details for the matches that were found. An empty pattern or empty test text with a supplied pattern prevents that evaluation.

Which regex flags are supported?

Use i, m, s, x, u, or a for the matching modes recognized by the tool. Other flag characters are ignored, so entering them does not change the matching mode.

What does a regex test with no matches mean?

If the evaluation is valid, zero means that the pattern found no match in the supplied text. If the evaluation fails instead, check whether the pattern is empty, the text is empty while a pattern is present, or the pattern cannot be compiled.

Tool

Regex Tester