Regex Tester & Debugger

Test JavaScript regular expressions online with match highlighting, capture groups, match positions and replacement preview.

All tools
developer Tool

Test and debug JavaScript regular expressions

developer Category Collection
JavaScript Regex Utility

Test, inspect and debug regular expressions

Your pattern and test text are processed in your browser. Nothing is sent to iToolsEra for regex matching.

Ready
0 characters
Enter the pattern without surrounding /slashes/. JavaScript RegExp syntax is used.
Flags
0 characters
Highlighted Matches No result yet

Run a regex to see highlighted matches.

Replacement Preview

Preview what JavaScript's replace operation would produce. Your original test text is never changed.

Preview Result

Enter replacement text and preview the result.

Maximum pattern length: 10,000 characters. Maximum test text: 200,000 characters. Long-running regex execution is isolated in a browser worker and stopped after a short safety timeout.

What Is a Regular Expression?

A regular expression, often called a regex, is a pattern used to find, match, extract or replace text that follows specific rules. Developers use regular expressions to locate identifiers, extract values, inspect text formats and replace repeated patterns.

This online JavaScript regex tester lets you test a pattern against sample text and inspect highlighted matches, match positions and capture groups. A regex that recognizes a particular text shape is not automatically a complete validator for the underlying data; for example, a date-shaped match does not prove that the date exists on a calendar.

How to Use the Regex Tester

  1. Enter a JavaScript regular-expression pattern in the pattern field.
  2. Select the flags you need, such as g for all non-overlapping matches or i for case-insensitive matching.
  3. Enter or paste representative text into the test area.
  4. Run the test and inspect highlighted matches, positions and captured groups.
  5. If the pattern is rejected, review the syntax and the error feedback.
  6. Enter replacement text and review the replacement preview when testing find-and-replace behavior.

Start with a small sample, then test additional cases such as empty input, unexpected characters and multiline text.

Regex Syntax Reference

SyntaxMeaningExample
.Any character except a line terminator by defaulta.c
\dDigit\d+
\wWord character\w+
\sWhitespace\s+
^Start anchor; line-aware with m^Hello
$End anchor; line-aware with mworld$
*Zero or more repetitionsa*
+One or more repetitionsa+
?Optional quantifier or lazy modifier, depending on contextcolou?r
{n}Exactly n repetitions\d{4}
[...]Character class[abc]
(...)Capturing group(\d+)
(?:...)Non-capturing group(?:cat|dog)
|Alternationcat|dog

Regex syntax can vary by engine. These examples use JavaScript regular-expression syntax.

JavaScript Regex Flags

FlagPurpose
gFind all non-overlapping matches rather than stopping after the first.
iIgnore case differences.
mMake ^ and $ work at line boundaries in multiline input.
sAllow the dot to match line terminators.
uEnable Unicode-aware regular-expression behavior.
yRequire matching at the current regular-expression position.

The g and y flags have different matching behavior and are not interchangeable.

Common Regex Examples

These examples are starting points, not universal validators. Real-world data formats can require additional rules.

  • Find numbers: \d+
  • Find date-shaped text: \b\d{4}-\d{2}-\d{2}\b
  • Find repeated whitespace: \s+
  • Find hashtags: #[A-Za-z0-9_]+
  • Capture two words: ^(\w+)\s+(\w+)$

The date example matches a YYYY-MM-DD-shaped string but does not verify calendar validity.

Understanding Capture Groups

Parentheses create capturing groups in JavaScript regular expressions. For example, (\d{4})-(\d{2})-(\d{2}) applied to 2026-10-12 captures the year, month and day separately. The full match contains the complete date, while each numbered group contains one part.

Use (?:...) when you need grouping behavior without creating a numbered capture. Inspecting the captured values can help explain why a pattern extracts an unexpected portion of the input.

Debugging Common Regex Problems

No matches: Check spelling, escaping, anchors, whitespace and case sensitivity. A valid pattern can return zero matches for a particular sample.

Only one match: Enable the g flag when you want all non-overlapping matches.

Dot misses line breaks: JavaScript does not make . match line terminators by default; consider the s flag.

Anchors behave unexpectedly: Check whether the m flag is appropriate for line-by-line matching.

Invalid pattern: Check unmatched brackets or parentheses, quantifiers and escape sequences.

Pattern works elsewhere but not here: Regex engines differ. This tool uses JavaScript RegExp, not a PHP/PCRE, Python or .NET interpreter.

Regex Replacement Preview

The replacement preview uses JavaScript string-replacement behavior. Replacement strings can reference captured groups with tokens such as $1 and $2. Without the g flag, a standard replacement generally changes only the first match; with g, it can replace all matching occurrences.

The preview is non-destructive: it shows the proposed result without overwriting the original test text. Review the output before using it elsewhere.

JavaScript Regex vs Other Regex Engines

Regular-expression syntax and supported features vary between languages and engines. This tool uses the browser's JavaScript RegExp implementation. A pattern copied from PHP/PCRE, Python or .NET may require changes before it behaves the same way in JavaScript.

When debugging a pattern for a specific application, test it in the same regex flavor used by that application before relying on the result.

Regex Performance and Safety

Some regular expressions can perform excessive backtracking on particular inputs. This tool runs regex execution inside a browser Web Worker and uses a timeout to stop tests that run too long. Input and match limits also help protect browser responsiveness.

If a test times out, try a smaller sample, simplify nested quantifiers and reduce ambiguous alternatives. A successful short test does not guarantee efficient behavior for every possible input.

Are My Regex and Test Data Uploaded?

Regex compilation, matching and replacement preview are performed in your browser. The tool does not send the regex pattern or test string to iToolsEra for matching. Avoid pasting passwords, private keys or other sensitive information into online tools unless your security requirements allow it.

Frequently Asked Questions

A regex tester lets you test a regular expression against sample text and inspect the resulting matches. This tool also displays capture groups and match positions and provides a replacement preview for JavaScript regular expressions.
This tool uses the JavaScript RegExp engine provided by your browser. It is not a general PHP/PCRE, Python or .NET regex interpreter.
Check the pattern, escaping, anchors, whitespace and case sensitivity. Also check whether flags such as i or m are needed. A pattern can be syntactically valid and still return zero matches for the supplied text.
JavaScript matching generally returns the first match when global matching is not enabled. Select the g flag when you want the pattern to find all non-overlapping matches.
Text inside parentheses creates a numbered capture group. For example, (\d{4})-(\d{2}) captures the year and month from 2026-10. The tool lists captured values for each match.
Yes. Paste multiline text into the test area. Use the m flag when you need ^ and $ to work relative to individual lines, and the s flag when you want a dot to match line terminators.
Yes. Enter replacement text and use the replacement preview to inspect JavaScript replacement behavior, including capture references such as $1 and $2. The preview does not overwrite the original test input.
No. This tool uses JavaScript RegExp. Patterns written for PHP/PCRE, Python or another engine may need to be adapted and tested in their target environment.
Regex matching and replacement preview run in your browser; the pattern and test text are not sent to iToolsEra for matching. Avoid entering sensitive data unless your security requirements permit it.
Some patterns perform excessive backtracking on particular inputs. The tool runs regex execution in a browser worker and stops tests that run too long. Simplifying nested quantifiers and ambiguous alternatives may help.