Developer / Free browser tool
Regex Tester with Live Highlights
The browser's own regex engine, your text, and the matches marked in place. Flags, named groups and a replacement string are one keystroke away.
No account or install. Tool input is processed on your device.
Type the pattern body only. The surrounding slashes are decoration.
g every match, i ignore case, m line anchors, s dot matches newline, u unicode, y sticky.
Spaces, tabs and newlines are preserved in the output pane.
Invalid pattern.
$& whole match · $1 group one · $<name> named group · $$ a literal dollar sign.
Only the first match is replaced unless g is on.
Match list
Offsets count UTF-16 code units, the same number String.prototype.match reports
| # | Index | Match | Capture groups |
|---|
Cheat sheet
| Characters | Matches |
|---|---|
| \d | A digit, 0 to 9 |
| \w | Letter, digit or underscore |
| \s | Whitespace, including newlines |
| . | Any character except a line break |
| [abc] | One of a, b or c |
| [^abc] | Anything except a, b or c |
| a|b | a or b |
| \b | A word boundary, zero width |
| Structure | Meaning |
|---|---|
| * | Zero or more of the previous token |
| + | One or more |
| ? | Zero or one, or makes a quantifier lazy |
| {2,4} | Between two and four repetitions |
| (abc) | Capture group, numbered left to right |
| (?:abc) | Group without capturing |
| (?<name>abc) | Named capture group |
| ^ $ | Start and end of string, or of line with m |
| (?=abc) | Lookahead: abc must follow, not consumed |
| (?<=abc) | Lookbehind: abc must precede, not consumed |
About this tool
Enter a pattern and test text to see matches highlighted in place. The tester uses the browser's JavaScript RegExp engine and lists each match's offset, full text and capture groups, including named groups.
The output pane is built from text nodes, preserving spaces, tabs and newlines without interpreting test input as HTML. Flag controls map to g, i, m, s, u and y, and invalid patterns show the engine's error message.
The replace field uses String.replace with the same pattern and flags. The replacement syntax supports $& for the whole match, $1 for a numbered group and $
What each flag changes
g keeps searching after the first match; without it, every operation sees only the first one. i folds case. m makes ^ and $ match line boundaries instead of the ends of the string. s lets . match a newline. u switches on Unicode mode, which changes how surrogate pairs, \p{...} classes and escape errors are handled. y is sticky: it anchors the search at lastIndex instead of scanning forward.
The chips above the test string are the same flags the engine accepts, in the same order. The suffix inside the pattern field shows what will actually be passed to new RegExp.
Why zero-length matches matter
A pattern such as \b, a* or (?:) can match at a position without consuming a character. In a global loop, exec then returns the same empty match at the same index forever, which is how a regex tester locks up a tab. This page advances lastIndex by one code unit whenever a match is empty, so the loop always terminates.
The zero-width matches are still reported in the list, because their count is part of the answer. In the highlight pane they draw nothing, which is correct: there is no character to mark.
This runs JavaScript's RegExp, so a pattern that works here works in new RegExp and nowhere else by default. PCRE, Python's re and Java's Pattern differ in the corners: atomic groups, possessive quantifiers and \A anchors do not exist in JavaScript, and lookbehind only arrived in ES2018.
How it works
Write the pattern
Type the body only: the slashes around the field are decoration. Pasting a full literal such as /abc/gi is a sign the flags belong in the chips instead.
Set the flags
The chips map one to one onto g, i, m, s, u and y. The count and the highlights update on every keystroke, and an invalid pattern reports the engine's own error message.
Read the matches
Each row lists the offset, the full match and the groups. The replace field shows what String.replace would produce with the same pattern.
Common questions
Why does my lookbehind fail?
Lookbehind, written (?<=...) or (?<!...), is part of ES2018 and works in current Chromium, Firefox and Safari. It fails in older engines and in some embedded runtimes. Atomic groups (?>...) and possessive quantifiers a++ are not JavaScript at all; they are PCRE.
What does the u flag change?
In Unicode mode a pattern is interpreted as a sequence of code points rather than UTF-16 code units, so a surrogate pair counts as one character, \p{Letter} and friends become available, and invalid escapes raise an error instead of matching a literal backslash.
Why is one of my matches empty?
Because the pattern can succeed without consuming a character, usually through \b, an optional group, or a quantifier that allows zero repetitions. The list shows an offset and no text for those. The tester advances past them so the next match can be found.
Does it support named groups?
Yes. Write (?<name>...) and the group appears in the list by name as well as by number, and $<name> works in the replace field. Numbers still apply, so both forms can be mixed.
Is my pattern or test text sent anywhere?
No. The pattern is compiled with new RegExp in this tab and the text never leaves it. There is no network request in the tool after the page has loaded.
Related tools
Timestamp converter
Paste an epoch value and read it six ways, or turn a date into seconds and milliseconds. The unit is detected, but never guessed silently.
Unit converter
Twelve categories, exact factors and one table that shows the same quantity in every unit. Pick two units, type a value, then click any row to look at it from the other side.
Color studio
One color written five ways, a palette built from tints, shades and harmonies, and a contrast checker that uses the WCAG 2.1 relative-luminance formula rather than a guess.