What This Tool Does

This regex tester evaluates your regular expression against a test string and highlights every match in real-time. It supports all JavaScript regex flags (g, i, m, s, u, y), shows capture groups for each match, and reports match positions. Perfect for debugging patterns before using them in code.

Inputs Explained

How It Works

The tool constructs a JavaScript RegExp with your pattern and flags, applies it to your test string with String.matchAll, and wraps every match in a highlighted span. Capture groups are extracted from each match and displayed with their position indices. Replacement preview uses String.replace.

Formula / Logic Used

re = new RegExp(pattern, flags) matches = [...text.matchAll(re)] highlight = text.replace(re, m => `${m}`)

Regex Tester & Debugger

Test and debug regular expressions with live match highlighting and capture group detail.

Step-by-Step Example

Pattern: \b\w+@\w+\.\w+\b | Flags: gi

Test: Contact alice@example.com or bob@test.co today.

Matches: 2 — alice@example.com (at index 8), bob@test.co (at index 29).

With replacement [EMAIL]: Contact [EMAIL] or [EMAIL] today.

Use Cases

Assumptions and Limitations

Disclaimer: Processing runs entirely in your browser. Your patterns and test strings are never uploaded.

Frequently Asked Questions

What regex flavor does this tool use?

JavaScript (ECMAScript) regex. Similar to PCRE but with some differences — no possessive quantifiers, named groups use (?) syntax, and some Unicode features require the 'u' flag.

What do the flags mean?

g = global (find all matches, not just first); i = case-insensitive; m = multiline (^ and $ match line starts/ends); s = dotall (. matches newlines); u = unicode (full Unicode support); y = sticky (match from lastIndex only).

How do I use capture groups in replacement?

Wrap parts of your pattern in parentheses to capture them, then reference as $1, $2, etc. in replacement. Example: pattern (\w+) (\w+), replacement $2 $1 swaps every two words.

Why does my regex work here but fail in Python?

JavaScript and Python regex differ slightly. Python uses (?P) for named groups (JS uses (?)), supports look-behind more broadly, and has (?i) inline flags. Check Python's re module docs for differences.

What is catastrophic backtracking?

Nested quantifiers like (a+)+ or .*.* can make a regex take exponential time on long strings. The tool runs in your browser, so a bad pattern may freeze the page. If it hangs, refresh and simplify the pattern.

How do I match special characters like . or +?

Escape them with a backslash: \. matches a literal period, \+ matches a literal plus. Characters that need escaping: . ^ $ * + ? ( ) [ ] { } | \ /.

Can I test multi-line regex?

Yes. Use the 'm' flag so ^ and $ match line starts/ends. Use 's' flag so . matches newlines too. Your test string can have as many lines as you want.

Is my pattern or test string stored?

No. Everything runs in your browser using native RegExp and String.matchAll. Nothing is sent to any server or stored.

Sources and References

Related Calculators

Find & ReplaceEmail ExtractorJSON FormatterCase ConverterURL EncoderHTML Entities