Regex Tester
Type a pattern, set the flags, paste the text, and every match is listed with its capture groups and its offset in the string, tinted in the text itself where there is something to tint. The matching is your own browser's JavaScript engine, used unchanged, so the answers here are the answers your code will give. Each run goes to a worker of its own with a timeout beside it, which is what lets this page test the patterns other testers cannot: a nested quantifier like (a+)+$ on text that does not match is stopped after 1.5 seconds and reported, rather than locking the tab with your sample text inside it.
Matches, groups and offsets appear here.
Waiting for a pattern and some text.
d record where each match starts and ends · g find every match, not only the first · i ignore upper and lower case · m ^ and $ match at every line · s a dot also matches a newline · u read the text as unicode code points · v unicode sets, with set operations in classes · y match only where the last one left off
- both, with offsets
- listed by name
- stopped by timeout
Common questions
- Why does my pattern only find the first match?
- Because the g flag is not set. Flags are passed to the engine exactly as you type them, so a pattern without g stops at the first match here for the same reason it does in your code. Add g to the flags box and the rest appear, each with its own offset.
- What happens if my pattern takes forever?
- It is stopped. Every run is posted to a worker created for that run alone, with a 1.5 second timeout armed beside it, and when the timeout fires the worker is terminated. You get a message saying the run was stopped and why, and the page, your pattern and your sample text are all still there. Catastrophic backtracking cannot be spotted before it happens and cannot be interrupted from the inside, so killing the thread it runs on is the only reliable stop.
- Does it show named capture groups?
- Yes, by name and by number. The group names are read from the pattern rather than from a match, so a pattern with (?<user>...) still names user among its groups when nothing matched at all, which is exactly when you want to see it. A group that took no part in a match is shown as no match, which is a different thing from a group that matched an empty string.
- Is this the same regex engine as my code?
- It is the JavaScript engine of the browser you are reading this in, used as it is. Regular expression syntax and behaviour are set by the JavaScript language itself, so an answer here carries over to Node and to other browsers, apart from the newest flags an older engine may not have yet. It is not PCRE, Python re or Go RE2: possessive quantifiers, recursion and atomic groups are not JavaScript syntax, and a pattern that needs them is reported here as invalid.
- How much text can I paste in?
- Up to 2,000,000 characters in one pass, and the first 5,000 matches are listed. Both numbers are stated on screen when you reach them: past the text ceiling the tool says so and names the size that arrived, and past the match ceiling it says the list is the first 5,000 rather than passing a partial count off as the total.
- Does my pattern or my text leave the page?
- No. There is no upload and no account: matching runs in your browser, in a worker built from this page's own code. Your pattern, flags and text are kept in your browser's local storage so the page opens where you left it, and the Start over button on this page forgets them.
Matching uses your browser's own JavaScript regular expression engine, so what you see here is what your code will do. It runs in a disposable worker with a timeout, so a pattern that would hang the page is stopped and reported instead.