Regex Tester
Enter a pattern and sample text — matches highlight as you type. The pattern and flags sync to the URL so you can share a link; your sample text never does.
Highlighted result
Matches (0)
Test JavaScript regular expressions against real text
This tool compiles a native RegExp from your
pattern and flags, wrapped in a try/
catch so a broken pattern shows a plain-language
error instead of a blank page. It then runs that expression
against your sample text exactly the way your own code would —
matchAll() when the global flag is checked,
collecting every match, or a single match() when
it isn't. Each match is highlighted in place by slicing the
original string around match.index and match[0].length and wrapping that slice in a <mark> element — never by search-and-replacing
the string, which breaks the moment your sample text contains
the characters being matched. Every match is also listed below
with its position and the text captured by any parenthesized
group.
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 — uncheck it and the
tool stops after the first, "alice@example.com," the same way String.prototype.match() would without the g flag.
Frequently asked questions
Why doesn't my pattern match across multiple lines?
Two separate JavaScript flags affect multi-line text, and it's easy to reach for the wrong one. m (multiline) changes what ^ and $ mean — with it on, they match the start/end of each line instead of only the start/end of the whole string. s (dotAll) changes what . matches — with it on, . also matches newline characters, not just "any character except a line break." A pattern that needs to span lines with .* usually wants s; a pattern anchoring each line with ^ or $ usually wants m. They're independent, and some patterns need both.
What does each flag actually do?
g (global) returns every match in the string instead of stopping at the first. i (ignoreCase) makes letters match regardless of case. m (multiline) makes ^ and $ match line boundaries, not just the string's start and end. s (dotAll) makes . match newlines too. u (unicode) treats the pattern as Unicode code points rather than raw 16-bit code units, which fixes matching for characters outside the Basic Multilingual Plane — most emoji, for instance — and unlocks Unicode property escapes like \p{Letter}.
Is this exactly the same regex syntax I'd use in Python, PHP, or grep?
No — this tool builds a real JavaScript RegExp, so it matches exactly how JS would behave, and JS regex is its own dialect. PCRE (which PHP uses, and which many other tools model themselves on) supports constructs JS lacks in some engine versions, like atomic groups and possessive quantifiers; JavaScript in turn has its own features, like named capture groups with (?<name>...) and lookbehind assertions, that older PCRE builds don't support. If the pattern is destined for a different language or tool, test it there too rather than assuming a match here is universal.
How do I read the capture groups in the results?
Each set of parentheses in your pattern captures whatever text matched inside it, numbered left to right starting at 1 (group 0, not shown separately here, is always the full match). For (\w+)@(\w+)\.com against "alice@example.com", group 1 captures "alice" and group 2 captures "example" — useful for pulling a username or domain out of a larger match without a second pass. A group that's part of the pattern but didn't participate in a particular match — inside an alternation that took the other branch, for instance — shows as unmatched rather than an empty string, and this tool marks that difference explicitly.