Regex tester
Test a regular expression against your text, see every match highlighted, and read a plain-English breakdown of what each part of the pattern does.
Runs in your browser
What this pattern does
Reading a pattern you did not write
Most regex problems are comprehension problems: someone pasted a pattern into a validator years ago and nobody since has been able to say what it accepts. The panel below the matches breaks the pattern into its constructs and names each one, in order and indented by group, so a pattern can be read rather than decoded.
Matches are highlighted in the test string as you type, which makes the common failures obvious at a glance — a pattern matching more than you meant, or matching in the middle of a word when you expected the whole of it.
Flags
| Flag | Effect |
|---|---|
g | Find every match, not just the first |
i | Ignore case |
m | ^ and $ match at each line break, not only at the ends of the text |
s | . also matches a line break |
u | Unicode mode: \u{…} escapes and \p{…} properties become available |
The m flag is the one most often wanted and least often set. Without it, ^ anchors to
the start of the whole subject, so a per-line pattern silently matches once and stops.
Greedy by default
.* and .+ take as much as they can and then give characters back until the rest of the
pattern fits. Against <b>one</b> <b>two</b>, the pattern <b>.*</b> matches the entire
string, not the first tag pair. Adding ? makes the quantifier lazy — <b>.*?</b> stops
at the first closing tag.
That single character is the difference between a scraper that extracts one field and one that extracts the whole document.
Catastrophic backtracking
Nested quantifiers over overlapping alternatives, such as (a+)+$, can take exponential
time on an input that does not match. A few dozen characters is enough to hang the engine
outright — and since this tester runs the pattern in your own tab, a pattern like that
will freeze this page too. It is the same failure that has taken down production services;
the usual fix is to make the inner alternatives mutually exclusive so the engine has
nothing to backtrack into.
Flavours differ
This page runs the browser’s own JavaScript engine, so what you see here is exactly what
RegExp will do. Other flavours are close but not identical:
- Lookbehind
(?<=…)is supported in JavaScript, Python and .NET, but not in Go’s RE2 or in most POSIX tools. \dmeans ASCII digits in JavaScript unlessuis set, but matches digits in every script in Python 3 by default.- Named groups are
(?<name>…)in JavaScript and .NET,(?P<name>…)in Python.
Test a pattern in the environment that will run it before trusting it in production.
Your data stays here
The pattern and the text are evaluated in your browser. Nothing is sent anywhere, which matters when the sample you are testing against is real log output or customer data.