Regex Tester
Test JavaScript regular expressions live with highlighted matches, capture groups, replacement and a plain-English explanation of every token.
| # | Position | Match | Groups |
|---|
Pattern explanation
Warning: a repeated group contains another open-ended quantifier, for example (a+)+. Such patterns can take exponential time on text that almost matches (catastrophic backtracking).
How to use the regex tester
- Type your pattern in Regular expression, without the surrounding slashes. The slashes and the active flags are shown around the field, as in
/pattern/g. - Tick the Flags you need:
g(global),i(ignore case),m(multiline),s(dotAll),u(unicode) ory(sticky). - Paste the text to search into Test text. Matches are highlighted as you type, and the table lists each match with its position and capture groups.
- To try a substitution, fill in Replacement. The Result after replacement box shows the text with every match replaced, ready to copy.
- Read the Pattern explanation to check what each part of your regex does. Not sure where to start? Click Load an example.
What the tester shows
- Highlighted matches: every match in the test text is marked, so you can spot what is caught and what is missed at a glance.
- Matches table: the number of each match, its position (character offset from the start, counting from 0), the matched text, and the value of every capture group. Named groups such as
(?<year>\d{4})appear under their name, and groups that did not take part in the match are shown as “(not matched)”. The first 1,000 matches are listed. - Replacement: the replacement text uses JavaScript syntax:
$1or$2for numbered groups,$<name>for named groups,$&for the whole match, and$$for a literal dollar sign. Without thegflag, only the first match is replaced. - Explanation: the pattern is split into tokens (literal text, character classes, anchors, groups, quantifiers, lookarounds, backreferences), each with a short description. Nested groups are indented, which makes long patterns much easier to review.
The flags in short
| Flag | Effect |
|---|---|
g |
Finds all matches instead of stopping at the first |
i |
Ignores the difference between upper and lower case |
m |
^ and $ match at the start and end of every line |
s |
. also matches line breaks |
u |
Full Unicode mode: \u{…}, \p{…} and emoji handled as single characters |
y |
Sticky: each match must start exactly where the previous one ended |
Catastrophic backtracking
Some patterns take exponential time on text that almost matches. The classic example is (a+)+$ tested against a long run of a followed by a b: the engine tries every way of splitting the as between the two quantifiers before giving up. This problem, known as ReDoS, has taken down real websites.
This tool protects your browser in three ways. The matching runs in a background worker that is stopped after 1.5 seconds; the test text is limited to 100,000 characters; and the explanation warns you when a repeated group contains another open-ended quantifier. When a pattern times out, rewrite it so that each character can be matched in only one way, for example a+$ instead of (a+)+$.
Frequently asked questions
Which regex flavor does this tool use?
It uses your browser’s JavaScript (ECMAScript) engine, exactly as new RegExp() and String.prototype.replace() would in your code. Most syntax is shared with PCRE, Python and Java, but some features differ: possessive quantifiers and atomic groups do not exist in JavaScript, and lookbehind is supported in all current browsers.
Why does my pattern find only one match?
The g flag is off. Without it, JavaScript stops after the first match, and the replacement only changes that one.
How do I match a literal dot, bracket or question mark?
Escape it with a backslash: \., \[, \?. The explanation shows escaped characters as “(escaped)” so you can check.
Is my text sent anywhere?
No. The pattern and the text are processed in your browser only, which makes this tool safe for log files or data that contains personal information.
Why is the position different from the column in my editor?
Positions count characters from 0, across all lines, the way JavaScript’s match.index does. Line breaks count as one character, and an emoji outside the Basic Multilingual Plane counts as two.
Related tools
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.
- URL Encoder and Decoder Free URL encoder and decoder. Percent-encode query parameters or full URLs, decode %XX sequences and handle + as space. Runs in your browser.
- Hash Generator Generate MD5, SHA-1, SHA-256 and SHA-512 hashes of text or files of any size, and verify checksums. Everything runs in your browser.