Regex Tester

Test and debug regular expressions with live matching and detailed match reports.

▲ Client-side only● No data sent to server✓ Free forever
Regex Pattern
Flags
Test String
Match Results
Ready

Tool guide

About Regex Tester

The Regex Tester checks a JavaScript regular-expression pattern against text you enter and lists matching strings with their positions. It can help debug a pattern on a sample, but a match does not prove that the expression is safe, complete, or suitable for every possible input.

Regex Tester runs a JavaScript regular expression against a sample string and lists each full match with its starting index. It is useful for exploring patterns and checking a few known examples before writing code. A successful sample is not proof that the pattern handles all inputs or performs safely on large, untrusted text.

How to use this tool

  1. 1Paste sample text into the test string field.
  2. 2Enter a JavaScript regex pattern without surrounding slashes and add supported flags such as `i` for case-insensitive matching. The tool adds the global `g` flag for match reporting.
  3. 3Select Find and review each matched substring and its index. If an error appears, check pattern syntax and whether the flags are valid together.

Main features explained

01Pattern and test string

Enter a JavaScript regex pattern without surrounding slash characters, then paste the sample text into Test String. The tool constructs a RegExp from those two fields when you select Find.

02Flags

Flags such as `i` for case-insensitive, `m` for multiline anchors, and `s` for dot-all may be entered. The function adds `g` because matchAll requires global matching and removes repeated flag characters before construction.

03Full matches and indexes

Each result reports the full matched string and its zero-based starting index in the JavaScript string. Capturing groups are not shown separately, and indexes count UTF-16 code units rather than user-perceived symbols.

04Syntax errors and empty input

Invalid expressions or unsupported flag combinations are caught and displayed as an error. If either the pattern or sample text is empty, the function returns an empty result rather than attempting a match.

How it works

The tool constructs a JavaScript `RegExp` from the entered pattern and flags, adds `g` if it is missing, then uses `matchAll` to collect full matches and their starting indices. Capturing groups are not separately reported, and invalid patterns or illegal flag combinations return an error message.

A quick example

The pattern `[a-zA-Z]+` matches runs of English letters. On the text `Hi, Sam!`, it finds `Hi` and `Sam` and reports where each begins.

Worked examples

Find runs of English letters

Before

Pattern: [a-zA-Z]+
Text: Hi, Sam!

After

Match 1: Hi (Index: 0)
Match 2: Sam (Index: 4)

The pattern accepts one or more ASCII letters. The index starts at zero, so the first character is position 0.

Case-insensitive matching

Before

Pattern: cat
Flag: i
Text: Cat cat CATALOG

After

Matches Cat, cat, and the cat at the start of CATALOG

The `i` flag ignores case. Because no word boundaries were added, the pattern can match within a longer word.

When it is useful

Test input validation patterns, search rules, and text-processing expressions against examples before adding them to code.

Learning a pattern

Try a small expression such as `[A-Z]+` against sample text and observe which runs match. Change one part of the expression at a time to see what it controls.

Checking input validation

Test a few valid and invalid-looking examples before adding a pattern to a form. Include edge cases such as empty strings, punctuation, whitespace, and Unicode input.

Finding repeated text fragments

Use the global matches to see every occurrence and its offset in a sample. If you need replacement groups or capture values, use a tester that reports those details or inspect the result in code.

Debugging flags and anchors

Try flags one at a time to understand how case, line boundaries, or dot matching changes results. Remember the global flag is applied automatically by this tool.

Tips for a better result

  • Start with a small sample where you know the expected matches, then add cases that should not match.
  • Use `^` and `$` carefully; line behavior can change with the `m` flag, and this tool adds `g` automatically.
  • Add word boundaries such as `\b` when you want to avoid matching inside longer words, and test them with punctuation and non-English text.
  • Treat indexes as JavaScript string offsets, not visible character positions, especially when emoji or combined characters are present.
  • Test potentially complex patterns on long or adversarial examples in the target runtime. Some expressions can take a long time due to backtracking.
  • Do not assume a match validates an email, URL, or other real-world format completely. Validation needs a clear specification and edge-case review.

Technical details and limits

The tester checks only the sample provided and does not prove a pattern handles all cases. Complex expressions can be slow or vulnerable to catastrophic backtracking in applications. Test representative and adversarial input in the target runtime.

The result depends on the text and options you provide. Keep a copy of the original when formatting matters, and review the output before using it in a document, site, or application. This guide describes the tool's behavior; it does not replace proofreading or checking a platform's own requirements.

Frequently asked questions

Why does the tool add a `g` flag?

It needs global matching to list multiple occurrences using `matchAll`.

Does it show capture groups?

The output reports full match text and index, not a separate breakdown of capture groups.

Does a successful test make my regex safe?

No. Test performance and edge cases, especially before using a pattern on untrusted large input.

Why is `g` added if I did not type it?

The implementation needs global matching to collect every result with `matchAll`.

Do I type the slashes around a regex?

No. Enter the pattern body in the pattern field and put flags in the flags field.

Does the result show capture groups?

No. It lists each full match and its starting index, not named or numbered capture values.

Why did my pattern match part of a longer word?

The pattern may allow substring matches. Add suitable boundaries and test them with punctuation and non-English text.

Does a successful match mean my regex is safe?

No. Test performance against long and adversarial inputs before running complex patterns on untrusted text.

Why do I see an error?

The pattern may be invalid JavaScript regex syntax, or the flags may be unsupported or incompatible. Read the displayed error and simplify the expression to find the issue.