Regex Tester and Builder
Test a pattern, then take it away as Python, Rust, Go or seven others.
Runs entirely in your browser
Loading the tool…
- —Matches
- —Capture groups
| At | Match | Groups |
|---|
Use it in your code
Write a pattern, paste your text, and every match is highlighted with its position and its capture groups listed. Start from one of the known patterns if you would rather not begin at a blank box, and press the tokens to insert the pieces you can never remember the spelling of.
Then take it with you. A pattern is not a string until it is
written into source, and every language writes it differently: Java doubles every
backslash, Go's raw string cannot contain a backtick, Rust widens its
r#"…"# until the pattern cannot close it early, and a shell needs the
'"'"' dance for an apostrophe. The snippet does that quoting for you,
which is the part that is fiddly rather than hard and goes wrong quietly.
Flavours differ, and the page says where. Rust's regex
and Go's regexp have no look-around and no backreferences, by design:
both guarantee linear time, and those features cost that guarantee. Ask for either
while your pattern uses them and the page tells you before you paste it into a build
that will fail.
Two of the four flags are named after each other's behaviour,
which catches people out in every language. m, multiline, changes what
^ and $ mean: they stop matching only the start and end of
the whole text and start matching at every line. s changes what
. means: normally it matches anything except a line break, and with
s it matches those too. Python calls that one DOTALL and C#
calls it Singleline, which is the opposite of what it sounds like it
does. Neither flag affects the other.
The testing itself runs on the regular expression engine your browser already carries, which is the JavaScript flavour. That is worth stating plainly: it is close to Python and PCRE for everything most patterns use, and it is not identical to any of them. Nothing compiled into this page would be either, which is why it uses the engine that is already here rather than shipping a third flavour to disagree with the other two.
How to use it
- Write a pattern, or choose one from the list to start from.
- Paste your text below it. Matches highlight as you type.
- Pick your language and copy the snippet, quoting and all.
Questions
Which regex flavour does the tester use?
JavaScript's, because that is the engine your browser already has. For the constructs most patterns use, character classes, quantifiers, groups, anchors, look-around and backreferences, it agrees with Python and PCRE. Where it differs is at the edges: possessive quantifiers, atomic groups and recursion are PCRE features JavaScript does not have, and named groups use the same syntax but not the same replacement syntax.
Why does it say Rust or Go cannot run my pattern?
Because those two engines have no look-around and no backreferences, and it is a deliberate omission rather than a gap. Both guarantee that matching takes time linear in the input, which rules out the backtracking those features need. If you want them in Rust, the fancy-regex crate adds both on top of the same engine at the cost of that guarantee.
What is the difference between the m and s flags?
They are the two most often confused, and they do unrelated things. m makes ^ and $ match at every line break rather than only at the start and end of the whole text. s makes . match a newline, which it otherwise never does. The naming is unhelpful everywhere: Python calls the second one DOTALL and C# calls it Singleline, which sounds like it should be the first one.
Does it handle named capture groups?
Yes. Write (?<name>…) and named groups appear in the table alongside the numbered ones. Support is good across languages but the syntax for referring to them afterwards is not: Python uses (?P<name>…) in some older code, and the replacement syntax differs almost everywhere.
Why is there no WebAssembly on this page?
Because compiling a regular expression engine into it would add about 290 KB over the wire to arrive at a different flavour from the one your code will use, and the browser already carries a perfectly good one. Every other tool on this site uses WebAssembly where it does real work; here it would be ceremony. The page still makes no network request and still works offline.
Is my text sent anywhere?
No. The matching happens in this tab and the page is served with a header forbidding it from opening a connection to anywhere at all. Test data tends to be real data, which is a good reason to check that before pasting a log into any tool of this kind.
Your data stays on your device
Everything above runs inside your browser as WebAssembly compiled from Rust. Nothing you type is uploaded, logged or stored on a server. You can load this page once, go offline, and it still works.
This page makes no requests at all, to anywhere. That is not a promise in the copy: it is a Content-Security-Policy header your browser enforces, and connect-src on it is none. Open the network tab and watch nothing happen.