Regex Builder
Regex Builder: Build it, break it, understand it.
Compose a pattern, test it against real text with every match highlighted, and get a line-by-line breakdown in English.
enter a pattern, matching runs in this browser
Nothing to match against
Paste text below, or load the sample. Matching runs locally as you type.
idle
enter a pattern to explain
0 chars
What this instrument does
Compose a pattern, run it against real text with every match highlighted and counted, and get a token-by-token breakdown written for someone who has never used a regular expression.
The matching runs in your browser using the browser's own engine. No pattern and no test text leaves the page unless you ask for an explanation.
How it works
- Testing is local and immediate
- Matching uses JavaScript's RegExp in the page, so results appear as you type without a request. Highlighted spans show position and length for every match.
- Explanations come token by token
- The breakdown walks the pattern left to right. Each row names the token, says what it matches, and explains why it is there.
- Rejection is a feature
- An invalid pattern reports which part failed, such as an unclosed bracket or a quantifier with nothing to repeat, instead of silently matching nothing.
Questions about Regex Builder
Questions
- Which regex flavour does this use?
- JavaScript's, because the matching happens in your browser. Lookbehind works in current Chrome, Safari, Firefox and Edge but not in older browsers. Python and PCRE syntax differ in places. Named groups use (?<name>…) rather than (?P<name>…).
- What do the flags do?
- g matches every occurrence rather than stopping at the first. i ignores case. m lets ^ and $ match at line boundaries. s lets . match newlines. u enables full Unicode handling, which matters for emoji and for astral-plane characters. Testing always runs with g so you see every match.
- How do I match an email address?
- A practical pattern is ^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(.[A-Za-z0-9-]+)*$ Note the unescaped dots inside the character class, where they are literals. RFC 5322 permits far more than that in practice, so treat this as a filter for obvious typos rather than a validator.
- Why does my pattern cause catastrophic backtracking?
- Because two quantifiers can match the same characters in more than one way, such as (a+)+ or a*a*. On a long non-matching input the engine tries an exponential number of paths. Make the inner quantifier possessive where the language supports it, make the alternatives mutually exclusive, or bound the repetition with {0,n}.
All instruments
Other instruments