breakitdown

Regex explainer and tester

Every token, colour-coded and explained in order. Hover a token or a line to see which is which. Flags where JavaScript and PCRE disagree, and a warning when a pattern can hang on hostile input.

flags: g all matches · i ignore case · m ^ $ per line · s . matches newlines · u Unicode

JavaScript ✓PCRE ✓

No catastrophic-backtracking patterns found. (A heuristic check: nested and adjacent repeats, overlapping alternatives.)

  1. ^Start of a line (the m flag makes ^ match after every line break)anchor
  2. (?<user>…)Named capturing group 'user' (#1)group
  3. [\w.+-]One character: a word character: a letter, digit or underscore (A-Z, a-z, 0-9, _), '.', '+' or '-'character class
  4. +Repeat the class one or more times, as many as possible (greedy)quantifier
  5. @The character '@' literallyliteral
  6. (?<domain>…)Named capturing group 'domain' (#2)group
  7. [\w-]One character: a word character: a letter, digit or underscore (A-Z, a-z, 0-9, _) or '-'character class
  8. +Repeat the class one or more times, as many as possible (greedy)quantifier
  9. (?:…)Non-capturing group: groups without rememberinggroup
  10. \.The character '.' literallyliteral
  11. [\w-]One character: a word character: a letter, digit or underscore (A-Z, a-z, 0-9, _) or '-'character class
  12. +Repeat the class one or more times, as many as possible (greedy)quantifier
  13. +Then repeat the whole group one or more times, as many as possible (greedy)quantifier
  14. $End of a line (the m flag makes $ match before every line break)anchor

2 capturing groups (named: user, domain).

Test it

2 matches

ada@example.com
not an email
grace.hopper@navy.mil
linus@kernel
#MatchAtGroup 1Group 2
1ada@example.com0adaexample.com
2grace.hopper@navy.mil29grace.hoppernavy.mil

Regex cheat sheet

TokenMeansNotes
.any character except a line breakwith s, line breaks too
\d \w \sdigit, word character, whitespacecapitals negate: \D \W \S
[abc] [^abc] [a-z]one of, none of, a rangemost metacharacters are literal inside [ ]
^ $start, endper line with m; PCRE $ also before a final newline
\bword boundaryinside [ ] it is a backspace
* + ? {n,m}0+, 1+, 0-1, n to m timesadd ? for lazy; PCRE + for possessive
(…) (?:…) (?<name>…)capture, group only, named capturePCRE and Python also accept (?P<name>…)
\1 \k<name>the text a group matched
a|ba or bleftmost alternative that works wins
(?=…) (?!…) (?<=…) (?<!…)lookahead, negative lookahead, lookbehind, negative lookbehindPCRE lookbehind must be bounded length
(?>…) \A \z \Q…\Eatomic group, string start/end, quotingPCRE only

Common patterns, explained