Paste a regular expression to see what it really does: every token explained in plain English, a railroad diagram of the pattern, notes on its flags, warnings about common mistakes and a live test box.
Last updated:
//
Railroad diagram
Token-by-token explanation
Flag notes
Copy as
Advertisement
Advertisement
How to use the Regex Explainer
Paste your regex into the box, either bare (\d{3}-\d{4}) or as a literal with slashes and flags (/\d+/g).
Read the summary and token list. Each row shows a piece of the pattern and what it matches; groups and alternatives are indented.
Follow the railroad diagram from the left dot to the right circle: boxes are things to match, branches are alternatives and loops are repetitions.
Check the flag notes and any warnings, then toggle flags to see how the meaning changes.
Try it on your own text in the test box to confirm the matches and captured groups.
Regex tokens at a glance
Token
Meaning
Example
.
Any character except a line break (any character with the s flag)
a.c matches "abc", "a-c"
\d\w\s
Digit, word character (A–Z, a–z, 0–9, _), whitespace
\d\d matches "42"
\D\W\S
The opposites: non-digit, non-word, non-whitespace
\S+ matches a word with punctuation
[abc][a-z][^0-9]
One character from a set, a range, or not in the set
[aeiou] matches one vowel
^$
Start and end of the string (of each line with m)
^Hi only at the start
\b
Word boundary
\bcat\b matches "cat" but not "category"
*+?
0 or more, 1 or more, 0 or 1 (optional)
colou?r matches both spellings
{3}{2,5}{2,}
Exactly 3, 2 to 5, 2 or more
\d{4} matches a year
*?+?
Lazy versions: as few as possible
<.+?> matches one tag
(…)(?<name>…)
Capturing group, named group
(?<year>\d{4})
(?:…)
Group without capturing
(?:ab)+
a|b
Alternation: a or b
cat|dog
(?=…)(?!…)
Lookahead: followed by / not followed by
\d+(?=px) matches "12" in "12px"
(?<=…)(?<!…)
Lookbehind: preceded by / not preceded by
(?<=\$)\d+ matches "5" in "$5"
\1\k<name>
Backreference: the same text a group matched
(\w)\1 matches "ll" in "hello"
\p{L}
Unicode property, here any letter (needs the u flag)
\p{L}+ matches "Grüße"
Reading an unfamiliar regex step by step
Long patterns become readable once you split them into parts. Look for the anchors first (^, $, \b), because they tell you whether the pattern must match the whole input or can appear anywhere. Next find the groups, since parentheses show what is captured and what a quantifier applies to. Then read each part from left to right, attaching every quantifier to the single token or group directly before it: in ab+ only the b repeats, in (ab)+ the pair repeats.
Character classes are the most common source of confusion. Inside square brackets most symbols lose their special meaning, so [.] is a literal dot, but ^ at the start negates the class and - between two characters makes a range. When in doubt, escape it with a backslash.
Frequently asked questions
Which regex flavor does the explainer use?
It follows JavaScript (ECMAScript) syntax, which is also very close to what most languages use for the common features: character classes, quantifiers, groups, lookahead and backreferences. Features that exist only in PCRE, Python or .NET, such as atomic groups, possessive quantifiers, inline (?i) flags and \A or \Z, are recognised and flagged as not supported in JavaScript.
How do I read a railroad diagram?
Start at the filled dot on the left and follow the lines to the circle on the right. Every box you pass must match in order. Where the line splits into branches, any one branch can match (alternation). A line that skips over a box means it is optional, and a line looping back underneath means it can repeat, with the number of repetitions written below.
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +, {n,m}) match as much as possible and then give characters back if the rest of the pattern fails. Lazy quantifiers (*?, +?, {n,m}?) match as little as possible and take more only when needed. For "a" "b", the pattern ".*" matches the whole text while ".*?" matches each quoted part separately.
What does catastrophic backtracking mean?
Patterns with nested repetition, such as (a+)+ or (\w+\s?)*, can try an exponential number of ways to split the text when a match fails. On long inputs this freezes the program. The explainer warns when it sees nested unbounded quantifiers; make the inner part more specific or use a single quantifier instead.
Why does ^ or $ not match each line?
By default ^ and $ match only at the start and end of the whole string. Add the m (multiline) flag to make them match at the start and end of every line.
Is my pattern or text uploaded?
No. Parsing, explaining, drawing the diagram and testing all happen in JavaScript in your browser.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.