Regex Tester
Enter a pattern and test string — matches highlight live. The pattern and flags sync to the URL for sharing; your test string never does.
Highlighted result
Matches (0)
Test JavaScript regular expressions against real text
This tool builds a native RegExp from your pattern
and flags, then runs it against your test string the same way
your own JavaScript code would — with matchAll()
when the global flag is on, or a single exec() when
it's off. Every match is highlighted in place, and each one is
listed below with its index in the string and the text captured
by any parenthesized groups.
Worked example
Pattern: (\w+)@(\w+)\.com, flags gu, against "Contact alice@example.com or bob@test.com for help."
-
Match 1 at index 8:
alice@example.com— Group 1:alice· Group 2:example -
Match 2 at index 29:
bob@test.com— Group 1:bob· Group 2:test
Two matches, because the global flag is on — without it, the tool would stop after finding "alice@example.com" alone.
Frequently asked questions
Why doesn't `.` match a newline in my test string?
By default, JavaScript's . matches any character except line terminators. If your test string spans multiple lines and you need . to match across them, turn on the s (dotAll) flag — with it on, . matches newlines too. Without it, a pattern like a.b will match "axb" but not "a\nb"; with the s flag, both match.
What does each flag do?
g (global) finds all matches instead of stopping at the first. i (ignoreCase) makes matching case-insensitive. m (multiline) makes ^ and $ match the start/end of each line, not just the whole string. s (dotAll) makes . match newlines too. u (unicode) treats the pattern as a sequence of Unicode code points, which fixes matching for characters outside the Basic Multilingual Plane (many emoji) and enables Unicode property escapes like \p{L}.
Is this JavaScript regex syntax specifically?
Yes. This tool builds a native JavaScript RegExp, so it follows JS regex rules exactly — which is not universal. Other tools and languages use different dialects: PCRE (used by PHP, and a superset many tools model themselves on) supports some syntax JS doesn't (like atomic groups and possessive quantifiers), and conversely JS has features PCRE lacks in older versions. If you're writing a pattern for grep, Python's re, or a PCRE-based tool, test it there too — don't assume a match here guarantees a match elsewhere.
How do capture groups work?
Parentheses in a pattern create a capture group — the text that group matched is pulled out separately from the full match. For example, (\w+)@(\w+)\.com against "alice@example.com" matches the whole string as group 0 (the full match), with group 1 capturing "alice" and group 2 capturing "example". This tool lists each group's captured text under every match.