/ pattern / flags

Regex Tester

Build and debug JavaScript regular expressions with safe isolated execution, precise matches, capture groups, replacement previews, and practical examples.

Worker timeoutNamed groupsLocal processing
//
Examples
JavaScript regular expressions

Build patterns from small, testable pieces

Start with literal text, add character classes and boundaries, then introduce repetition and groups. Test both expected matches and text that must not match.

Character classes

Choose allowed characters

\d matches digits, \s whitespace, and [A-Z] an ASCII uppercase range.

Quantifiers

Control repetition

*, +, ?, and {n,m} control how many times a token may repeat.

Groups

Capture useful parts

Use (...) or (?<name>...); use (?:...) when capture is unnecessary.

Boundaries

Constrain context

^ and $ anchor lines or input. \b identifies an ASCII-style word boundary.

Avoid catastrophic backtracking

Nested ambiguous repetition—such as repeated groups that can match the same characters in many ways—can make backtracking engines take exponential time. Prefer specific character classes, bounded quantifiers, and unambiguous alternatives. The timeout protects this page, but production code still needs carefully reviewed patterns.

Frequently asked questions

Which regular-expression flavor does this use?

Your browser’s JavaScript RegExp engine. Features can vary slightly with browser support, especially newer flags.

Why is the global flag important?

Without g, JavaScript stops after the first match. This tester respects that behavior and reports one match unless global matching is enabled.

What replacement tokens are supported?

JavaScript supports tokens including $& for the entire match, $1 for numbered groups, and $<name> for named groups.

Why did my test time out?

The pattern likely required excessive backtracking for the supplied text. Simplify ambiguous nested quantifiers or reduce the test case.