Regex Explainer: Break a Pattern Into Plain-English Parts
Paste a regular expression to split it into its syntax elements (character classes, quantifiers, groups, lookaheads and lookbehinds, anchors, escapes and flags) and read what each one does. It follows JavaScript regex syntax and reports syntax errors with their position. This tool only explains a pattern; it does not match it against text. To try a pattern on real input use the Regex Tester, or grab a ready-made one from the Regex Pattern Library.
🔒 Runs in your browser · Your data is never sent to a server
How to use
- Type or paste the pattern you want explained into "Regex pattern" (the /pattern/gi form works too).
- If you need flags, enter letters such as g i m s u v y in "Flags".
- Read the parts list below to see what each piece means and how groups nest.
- Use "Copy explanation" to save the text, or "Insert sample" to try an example.
Notes
- This explains JavaScript (ECMAScript) regex syntax. Other flavors such as PCRE, Python or Java differ on some features (possessive quantifiers, conditionals, \A and \z, and so on).
- The tool only explains a pattern; it never tests it against text. Use the Regex Tester to check behavior.
- Syntax errors show the character position (counting from 1). Anything the parser misses is caught with the message from the browser's own RegExp.
- The u and v flags make the syntax stricter, so a pattern that works without them (for example an unnecessary escape such as \a) can become an error.
- Contents of groups and character classes are indented. A quantifier applies to the one element before it, or the whole group up to its closing parenthesis.
Glossary
Quantifier (greedy / lazy)
Symbols such as * + ? and {n,m} that set how many times the previous element repeats. By default they match as much as possible (greedy); adding ? makes them match as little as possible (lazy).
Lookahead and lookbehind
Assertions that check what follows (lookahead) or precedes (lookbehind) without consuming characters. There are four forms: (?=...) (?!...) (?<=...) (?<!...).
Capturing group
Parentheses that remember the text their contents matched. Groups are numbered 1, 2, ... by their opening parenthesis and can also be named, then used in backreferences and replacements. Use (?:...) when you do not need to remember it.
Anchors and word boundaries
Elements such as ^ $ \b \B match a position rather than a character. They have zero width and consume nothing.
Unicode property escape
Syntax like \p{Letter} or \p{Script=Hiragana} that selects characters by their Unicode properties. It needs the u or v flag.
FAQ
Can this tool test whether a regex matches my text?
No. It only splits a pattern into syntax elements and explains them; it never matches against text. To try a pattern on real input, use the Regex Tester.
What is the difference between greedy and lazy quantifiers?
Quantifiers such as * + and {n,m} normally match as much as possible (greedy). Adding ? after them (*? +? {n,m}?) makes them match as little as possible (lazy). The explanation marks lazy quantifiers so you can tell them apart.
Does it explain PCRE or Python regular expressions?
It targets JavaScript (ECMAScript) syntax. Shared basics mean the same thing, but possessive quantifiers like a++, atomic groups (?>...), conditionals and \A \z do not exist in JavaScript, so they are reported as errors or read differently.
How is the error position counted?
It counts from 1 at the start of the pattern, and the offending character is highlighted. For an unclosed parenthesis or character class, the position points at the opening one.
Why does adding the u flag cause an error?
The u flag (and v) makes the syntax strict, so unnecessary escapes such as \a and bare { ] } become errors. Conversely, \p{...} and \u{...} only work in that mode.
Share this page
