Regex Tester
Test a regular expression against your text and see every match highlighted in place, with capture groups and positions listed. Runs in your browser.
Type a pattern and a test string, and see every match highlighted inside the text as well as listed individually with its position and capture groups. Matching uses the browser's own regular expression engine, so the behaviour is exactly what your JavaScript will do.
// Regex Tester: Features
Highlighting and a match list, together
Two views answer different questions. The highlighted text shows you where in the document the matches fall, which is how you spot a pattern that is matching more or less than you intended. The list shows each match separately with its index and any capture groups, which is how you confirm that the right part of the text is being captured. Having both at once is usually faster than reasoning about the pattern in the abstract.
The five flags
Global finds every match rather than stopping at the first, and is almost always what you want when testing. Case-insensitive is self-explanatory and is the fix for roughly half of all "why does this not match" questions. Multiline changes the anchors so they match at the start and end of each line rather than of the whole string. The dotAll flag makes the wildcard match newlines too, which is what you need when a pattern must span lines. The Unicode flag enables proper handling of characters outside the basic plane and of Unicode property escapes.
This is the JavaScript engine
Matching runs through the browser's built-in regular expression implementation, so what you see is precisely what the same pattern will do in your JavaScript. That is a feature when you are writing JavaScript and a caveat otherwise: PCRE, Python, Go and POSIX all differ in places. Lookbehind, named groups and Unicode property escapes are supported in current browsers, the last of these requiring the Unicode flag, but they behave differently or not at all in other engines, so verify a pattern in its destination language before relying on it.
Greedy quantifiers and catastrophic backtracking
By default a quantifier takes as much as it can and gives back only when forced, which is why a pattern intended to match one tag often swallows everything between the first and the last. Adding a question mark after the quantifier makes it lazy and fixes most of these cases. Separately, nesting quantifiers so that the engine can split the same text many ways produces patterns that take exponential time on input that nearly matches. If a pattern hangs the page on a long string, that is what has happened, and the fix is to restructure rather than to optimise.
Testing a pattern against real log data
The pattern and the test string are never transmitted, stored or logged. Log excerpts containing customer identifiers, internal URLs and production data can all be pasted here while you work out a pattern. The match list is capped at fifty entries so that a pattern matching thousands of times does not make the page unusable; the count above it tells you the real total.
// Regex Tester: FAQ
Which regex flavour does it use?
- The JavaScript engine built into your browser, which is exactly what your front-end code or Node.js will run. If your pattern is destined for Python, Go, PCRE or a database, test it there as well: the syntax overlaps heavily but escaping rules, lookbehind support and Unicode handling all differ.
Which flags are available?
- Five: global, case-insensitive, multiline, dotAll and Unicode. Global finds every match rather than the first; case-insensitive ignores letter case; multiline makes the anchors apply per line; dotAll lets the wildcard match newlines; and Unicode enables correct handling of astral characters and property escapes.
Why does my pattern match more than I expected?
- Almost always a greedy quantifier. A pattern that matches any characters between two delimiters will, by default, run from the first opening delimiter to the last closing one. Making the quantifier lazy by adding a question mark after it, or replacing the wildcard with a negated character class, fixes it.
Why does the page freeze on a long string?
- Catastrophic backtracking. When a pattern contains nested quantifiers that can divide the same text in many ways, the engine may explore an exponential number of possibilities before concluding there is no match. Restructure the pattern so that each position can only be consumed one way; possessive-style rewrites and anchoring both help.
Are capture groups shown?
- Yes. Each entry in the match list shows the full match along with the groups it captured, which is how you confirm that the parentheses are around the part you actually want. This is usually more informative than the highlighted view when the pattern is extracting rather than merely finding.
Why is only part of my text highlighted?
- Check the global flag first. Without it, matching stops after the first result. If global is on and later occurrences still are not matched, the pattern is probably anchored, or a quantifier earlier in the pattern has consumed more of the string than you intended.
Why are only fifty matches listed?
- To keep the page responsive when a pattern matches thousands of times. The count above the list is the true total, and the note at the end of the list says how many were not shown. If you are only interested in whether a pattern matches at all, the count is the number to read.
Do I need to escape the delimiters?
- No. You type the pattern body only, without the surrounding slashes, so a forward slash inside the pattern needs no escaping here. Remember to add the escaping back if you paste the pattern into JavaScript source using literal syntax.
Is it safe to test against production data?
- Yes. Both the pattern and the test string stay in your browser and are never transmitted, stored or logged. Pasting a genuine log excerpt is usually the only way to get a pattern right, because real data contains the edge cases invented examples omit.
Are my pattern and test string sent to a server?
- No. Matching runs entirely in the page, and closing the tab discards both the pattern and the text.
// How to Use Regex Tester
-
Enter your pattern
Type the regular expression into the pattern box, without the surrounding slashes. An invalid pattern is reported rather than silently failing to match.
-
Set the flags and paste your text
Turn on the global flag to find every match, case-insensitive if letter case should not matter, and multiline if your anchors should apply per line. Then paste the text you want to test against.
-
Read both views
The highlighted text shows where the matches fall, which reveals a pattern matching too much. The match list shows each result with its capture groups, which confirms you are extracting the right part.
Category Code