Regex Tester & Debugger
Live matching on the real engines of JavaScript, PCRE2 (PHP), Python, Go, Rust and Oniguruma, compiled to WebAssembly, a step-by-step backtracking debugger, a plain-English explanation of every token, a railroad diagram, a catastrophic-backtracking check, saved unit tests, code for ten languages, and a pattern generator that learns from your examples, all in your browser.
Type a pattern above to see it explained token by token.
The diagram shows every path a string can take through the pattern: follow a line from the left circle to the right circle.
Runs the pattern and test string on JavaScript, PCRE2, Python, Go, Rust and Oniguruma, each the real engine compiled to WebAssembly, and shows where they disagree: a pattern that works in one language can fail to compile, or match differently, in another.
Traces how a backtracking engine (JavaScript's rules) tries the pattern on the first 1,000 characters of the test string: every token tried, every success and failure, and every step back.
Static analysis of the pattern structure: nested unbounded repeats, overlapping alternatives under a repeat, and adjacent repeats that accept the same characters — the three shapes behind nearly every regex denial-of-service.
Tests live in the share link, so a reviewer gets the pattern and its expectations together. "Whole string" requires the match to cover the entire input; a group check compares a numbered or named group with an expected value.
| Input | Expect | Group | Value | Result |
|---|
Drop a log, CSV or any text file here. Each line is tested separately; you get the count of matching lines, the first matches, and a download of only the lines that matched. Files up to about 50 MB are fine.
Paste strings that should match and strings that should not, one per line. The generator finds the shape the positive examples share (runs of digits, letters, separators), keeps literal parts they all have in common, and ranks candidates by how many examples each gets right. It is rule-based and runs locally; it is good at identifiers, codes, dates and keys, less good at free text.
. | any char except newline (s: any) |
\d \w \s | digit · word char · whitespace |
\D \W \S | their negations |
[abc] [^abc] | one of · none of |
[a-z0-9] | ranges |
\p{L} \p{Script=Han} | Unicode property (needs u) |
\t \n \r \xHH \uHHHH \u{H…} | escapes |
* + ? | 0+ · 1+ · 0 or 1 |
{n} {n,} {n,m} | exact · at least · range |
*? +? ?? {n,m}? | lazy versions |
(…) | capture group |
(?:…) | non-capturing |
(?<name>…) | named group |
\1 \k<name> | backreference |
a|b | alternation |
(?i:…) (?-i:…) | inline modifiers (ES2025) |
^ $ | start · end (line with m) |
\b \B | word boundary · not |
(?=…) (?!…) | lookahead · negative |
(?<=…) (?<!…) | lookbehind · negative |
$1 $<name> | group |
$& | whole match |
$` $' | text before · after |
$$ | literal $ |
g | all matches |
i | ignore case |
m | multiline anchors |
s | dot matches newline |
u | Unicode mode |
y | sticky |
d | group indices |
v | set notation (ES2024) |
A debugger, not just a tester
A regex tester tells you whether a pattern matches. A debugger tells you why, what it will do on the inputs you have not tried yet, and how to carry it into the language it will actually run in. The tabs above are that difference.
Explain and diagram
The pattern is parsed into a tree and every token described in plain English — what a character class contains, how greedy a quantifier is, which group number a capture gets. The railroad diagram draws the same tree as paths, which is the fastest way to spot an alternation that swallows more than intended.
Safety analysis
Nested unbounded repeats like (a+)+, overlapping alternatives under a repeat like (\w|\d)*, and adjacent repeats that accept the same characters are flagged with the exact fragment and a rewrite. The growth test then measures engine time as the input doubles, which is the empirical confirmation.
Tests that travel
Unit tests — should match, should not, whole-string, group equals — live in the share link alongside the pattern, so the person reviewing your change can run them, and the person editing the pattern next year can see what it was meant to accept.
Code for ten languages
Flags become re.IGNORECASE, RegexOptions.Multiline or (?im); named groups become (?P<name>) where needed; and anything the target engine cannot do — lookbehind in Go, backreferences in Rust — is called out before you paste it.
Whole-file batch runs
Drop a log or export and test every line. You get the number of lines that matched, the first few with their captures, and a download of only the matching lines — the quick filter you would otherwise write a script for.
Patterns from examples
Give it a handful of strings that should match and a few that should not; it infers the shared shape, keeps literal parts in common, and ranks candidates by the examples they get right. A starting point you then refine with the tests tab.
Quick Testing Templates
Click a template to load a pattern and test string. The last one is deliberately dangerous: open the Safety tab after loading it.
Common regex patterns (cheat sheet)
Ready-made regular expressions for the things people validate most often: email addresses, URLs, IP addresses, phone numbers, dates, UUIDs and more. Press Try to load one into the tester with sample text that includes both matches and near misses, then adapt it. Every pattern here is written for JavaScript and also runs unchanged on the PCRE2, Python, Go and Rust engines in the Engines tab, except the back-reference and lookahead ones, which Go and Rust do not support.
| Matches | Pattern | Notes | Load |
|---|---|---|---|
| Email address | ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ | A practical check for addresses like name@example.com. Full RFC 5322 allows more, but almost no real form needs it. | |
| URL (http or https) | https?://[^\s/$.?#][^\s]* | Finds web links in running text, up to the next space. | |
| IPv4 address (0-255) | \b(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\b | Each part limited to 0-255, so 999.1.1.1 is rejected. | |
| MAC address | \b(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}\b | Six hex pairs separated by colons or hyphens. | |
| Phone number (international, E.164) | ^\+[1-9]\d{6,14}$ | A plus sign, a country code and up to 15 digits in total, with no spaces. | |
| UAE mobile number | ^(?:\+971|00971|0)5[024568]\d{7}$ | 050, 052, 054, 055, 056 and 058 numbers, with +971, 00971 or a leading 0. | |
| Indian mobile number | ^(?:\+91|0)?[6-9]\d{9}$ | Ten digits starting 6-9, optionally with +91 or 0 in front. | |
| Date (YYYY-MM-DD) | \b\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])\b | ISO 8601 dates with a valid month and a day from 01 to 31. It does not know that 31 February does not exist. | |
| Time (24-hour HH:MM) | \b(?:[01]\d|2[0-3]):[0-5]\d\b | 00:00 to 23:59. | |
| Hex colour | #(?:[0-9a-fA-F]{3}){1,2}\b | #rgb or #rrggbb in CSS. | |
| UUID / GUID | \b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b | Versions 1 to 8 with the RFC 9562 variant, in either case. | |
| Strong password rule | ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{12,}$ | At least 12 characters with a lower-case letter, a capital, a digit and a symbol. Length matters more than the mix; see the password guide. | |
| URL slug | ^[a-z0-9]+(?:-[a-z0-9]+)*$ | Lower-case words joined by single hyphens, as in a blog post address. | |
| Username (3-16 characters) | ^[a-zA-Z0-9_]{3,16}$ | Letters, digits and underscores only. | |
| US ZIP code | \b\d{5}(?:-\d{4})?\b | Five digits, optionally followed by a hyphen and four more (ZIP+4). | |
| Indian PIN code | \b[1-9]\d{5}\b | Six digits that do not start with 0. | |
| Repeated word | \b(\w+)\s+\1\b | Finds typos like "the the" using a back-reference. | |
| Leading or trailing spaces | ^[ \t]+|[ \t]+$ | Use with an empty replacement to trim every line. | |
| HTML tag | </?[a-zA-Z][^>]*> | Opening and closing tags. Fine for a quick look; use a real HTML parser to process HTML. |
A pattern that validates input should be anchored with ^ and $ (and the m flag when you test one value per line); a pattern that searches running text should not. For anything that has to be exact, such as an email address you will send mail to, use the pattern as a first check and confirm by other means.
Test the failing case, not just the passing one
Most regex bugs are not "the pattern does not match" — they are "the pattern matches slightly more than intended", or "the pattern takes four minutes on one particular input". Both are invisible if you only ever test with an example that works.
The second category is worth taking seriously. Backtracking engines — JavaScript, Python's re, Java, .NET, PCRE — can take exponential time when a pattern is ambiguous, meaning there is more than one way to divide the same input between its parts. A pattern like ^(a+)+$ tested against thirty as followed by one X takes roughly a second; at forty characters it is about fifteen minutes. Our guide on catastrophic backtracking explains the mechanism and the fixes; the Safety tab applies those rules to your pattern automatically.
Nested quantifiers
(a+)+, (\d+)*, ([a-z]+)*. A quantifier immediately outside a group whose contents also repeat is exponential. It usually has a trivially equivalent safe form — (a+)+ matches exactly what a+ matches.
Ambiguous alternation
(\w|\d)* is dangerous because \d is contained within \w, so every digit can match two ways. Make alternation branches mutually exclusive, or collapse them: \w*.
Optional separators in a repeat
(\w+\s?)+$ appears in countless "validate a full name" patterns and is polynomial. Make the separator mandatory between tokens instead: ^\w+(\s\w+)*$.
Flags change the answer, not just the search
Three flags cause most of the confusion when a pattern behaves differently than expected:
g(global) — withRegExp.test()orexec(), a global regex carries mutablelastIndexstate between calls, so callingtest()twice on the same string can returntruethenfalse. Never reuse a global regex object across calls unless you intend that.m(multiline) — changes^and$to match at line boundaries rather than only at string boundaries. Without it,$anchors to the very end of the input.s(dotAll) — makes.match newlines, which it otherwise does not. This is why a pattern that works on one line silently fails across a wrapped block of text.
Capture groups are the other common source of surprise: (...) captures and is numbered left to right by opening parenthesis, (?:...) groups without capturing, and (?<name>...) captures by name. Adding a group in the middle of a pattern renumbers everything after it, which quietly breaks any code indexing matches positionally. Named groups avoid that entirely — and the Explain tab shows you every group's number at a glance.
The replacement preview
Substitutions have their own hazards. $1 inserts the first capture group, $& the whole match, and $$ a literal dollar sign — so a replacement containing a currency amount needs escaping. Previewing the result against real input is faster than reasoning about it, especially when the replacement references groups whose numbering you have just changed.
One pattern, several engines
Regular expressions are not one language. JavaScript, PCRE (PHP, grep -P), Python, Java, .NET, Go's RE2 and Rust's regex crate agree on the core — classes, quantifiers, groups, anchors — and disagree at the edges. Go and Rust guarantee linear time by refusing lookaround and backreferences entirely. Python spells named groups (?P<name>…). Ruby's ^ is always a line anchor. POSIX sed has no \d. The Code tab translates what it can and names what it cannot, which is the part that otherwise costs an afternoon.
Local, which matters for this tool
The text people test patterns against is usually the real thing: production logs, customer exports, source code. All matching here is done by the JavaScript engine in your browser tab; nothing is posted anywhere. The files you drop in the batch tab are read with the browser's FileReader and never leave your machine.
Technical FAQ
You choose. JavaScript runs on your browser's own engine. PCRE2 (used by PHP's preg functions, R and nginx), Python's re module, Go's regexp, Rust's regex crate and Oniguruma run as the real engines of those languages compiled to WebAssembly, so a match or a syntax error is exactly what that language gives you, not an imitation. Python's engine is CPython itself, through Pyodide, and downloads about 13 MB the first time you pick it. Java and .NET have no engine that can run inside a web page, so for them the Code tab lists the features that differ. The Engines tab runs one pattern on every engine at once and marks where they disagree.
The Debugger tab runs the pattern on a traced backtracking matcher that follows JavaScript's rules and records every step: each token tried at each position, whether it matched, and every time the engine gives back characters from a repeat or moves to the next alternative. Step through with the arrows or drag the slider; the current token is marked in the pattern and the current position in the text. A pattern that backtracks catastrophically stops at 100,000 steps, which shows the problem far more directly than a timeout.
The pattern is parsed into a tree and scanned for three shapes: an unbounded repeat containing another unbounded repeat, alternatives under a repeat whose first characters overlap, and two adjacent repeats that can accept the same characters. Each finding shows the fragment and a safer rewrite. The growth measurement then runs the pattern on your test string at one, two, four and eight times its length and reports how the time grows: roughly doubling is linear and fine, quadrupling or worse means the ambiguity is real.
A transparent textarea captures your keystrokes while a perfectly aligned layer behind it renders the colourised matches and mirrors the scroll position. Alternate matches use two shades so adjacent matches stay distinguishable, and the match list below shows every capture group with its index range.
The syntax of the engine you picked, because each language writes replacements differently. JavaScript uses $1, $<name>, $& for the whole match and $$ for a dollar sign; PCRE2, Go and Rust use $1 or ${1} and ${name}; Python uses \1, \g<1> and \g<name>. The preview is produced by that engine's own replace function and respects the g flag, so without it only the first match is replaced.
In the page, and in the share link when you copy one: the pattern, flags, test string and the full test table are compressed into the URL fragment, which browsers never send to a server. Paste the link into a code review or a ticket and the reader gets the pattern with its expectations and can run them. Nothing is stored on Layerbit's side. History is off by default; if you turn on Save to history, runs you save with Save run or Ctrl+Enter are kept in your browser's own storage.
It is a rule-based synthesiser, not a language model. It splits each positive example into runs of digits, letters, whitespace and punctuation, checks whether all examples share the same sequence, and builds patterns from that shape with exact, loose and unanchored variants, then scores each candidate against your negative examples. For structured strings such as invoice numbers, SKUs, dates, keys and identifiers it produces a usable pattern immediately; for free text it gives you a starting point to edit.
If you are testing patterns against proprietary application logs or databases containing personal information, pasting that text into a server-side tool is a data transfer you may not be allowed to make. Everything here, including the batch file mode, runs in your browser, and the header indicator counts the network requests the page makes so you can see that it stays at zero.
Deployment Changelog
- v3.3.0 Real engines for other languages, compiled to WebAssembly: PCRE2 10.49, Python's re (CPython through Pyodide), Go's regexp, Rust's regex crate and Oniguruma, with matches, groups, errors and the replace preview from that engine; an Engines tab that runs every engine side by side; and a step-by-step backtracking debugger.
- v3.2.0 The safety check no longer reports a nested repeat as high risk when every repetition must match a delimiter the inner part cannot match, as in the domain pattern ^([a-zA-Z0-9]+\.)*[a-z]+$ (it runs in linear time); (\d+)* and similar patterns are still flagged.
- v3.1.0 History is off by default: with the Save to history switch on, runs are saved only with Save run or Ctrl+Enter, never while typing.
- v3.0.0 Rebuilt as a debugger: token-by-token explanation, railroad diagram with SVG export, static catastrophic-backtracking analysis plus a growth measurement, saved unit tests that travel in share links, code generation for ten languages with engine caveats, whole-file batch testing with download, pattern synthesis from examples, a quick reference, match export as text/CSV/JSON, and alternating match colours.
- v2.4.0 Added an engine-time readout that flags slow patterns, and a line-number gutter.
- v2.3.0 Added the s, u and y flags and the replacement preview with named-group support.
- v2.2.0 Match list shows numbered and named capture groups with index ranges.
- v2.0.0 Dual-layer live highlighting editor.