Regex Tester
Matches
| # | Match | At | Groups |
|---|
Replace
Explain
Why a regex tester needs a time limit
Some patterns are slow in a way that has nothing to do with how long your text is. The shape
(a+)+b against a string of a's that never reaches a b makes the engine try
every way of splitting the a's — and the number of ways doubles with each character. Twenty-five
characters can take longer than you will wait.
That is catastrophic backtracking, and it is a real denial-of-service class in production code, not just an inconvenience. Here the matching runs in a background thread that can be stopped, so a pattern like that reports a timeout instead of hanging the tab. If it times out here, it will hang your server too — that is worth knowing before you ship it.
The mistakes that come up most
- Forgetting
g— without it you get the first match only. .does not match a newline unless you adds.\wis only[A-Za-z0-9_]— no Devanagari, no accents. Useuwith\p{L}.- Greedy by default —
<.*>swallows to the last>; write<.*?>. - Unescaped dots —
.matches any character, soexample.comalso matchesexampleXcom.
Regular expressions are not parsers
HTML, JSON and nested brackets are not regular languages, and no pattern handles them correctly in every case. Use a parser for those. Regular expressions are excellent for what they are for: finding and extracting flat, predictable shapes in text.
Share this tool with friends
Free to use, no sign-up, works on any phone.
Frequently Asked Questions
JavaScript, because that is what runs it. Most of what you write will behave the same in PCRE or Python, but lookbehind support, named groups and the treatment of Unicode differ, so verify anything critical in the language you will actually ship.
Because it was taking too long. Certain patterns — nested quantifiers over a long string, the classic (a+)+ shape — can take effectively forever on input that does not match. The matching runs in a separate thread with a time limit, so instead of freezing the page it stops and tells you.
g finds every match rather than the first, i ignores case, m makes ^ and $ match at line breaks, s lets a dot match a newline, u turns on proper Unicode handling.
Because \w means only [A-Za-z0-9_]. For Devanagari or any other script, turn on the u flag and use \p{L} for letters and \p{M} for the matras — leaving \p{M} out splits Hindi words in the middle.
No. The pattern and the text stay in your browser. Nothing is uploaded, which matters when you are testing against a log or a real data sample.
The first capture group. $2 is the second, $& the whole match, and $$ a literal dollar sign. Named groups can be used as $<name>.