Skip to content
gohacks.dev
Tooling

Regex Explainer

Paste a regular expression and read what each token does in plain English: groups, classes, quantifiers, anchors, lookarounds and backreferences.

Free · No sign-up · Your inputs stay in your browser

Input

Explain a regular expression

Output

15 parts

TokenMatches
^the start of the string (or line, with the m flag)
(?<user>start capturing group 1, named user
[\w.+-]one of word characters.+-
+repeat the previous item one or more times
)end the group
@the literal character @
(start capturing group 2
[a-z0-9-]one of a-z0-9-
+repeat the previous item one or more times
\.a literal .
)end the group
+repeat the previous item one or more times
[a-z]one of a-z
{2,}repeat the previous item 2 or more times
$the end of the string (or line, with the m flag)

Explains JavaScript and PCRE syntax token by token; indentation shows group nesting. Flavour differences matter at the edges: possessive quantifiers and (?P<name>) are PCRE (PHP) only, and lookbehind needs a modern engine.

Runs in this browser. Nothing you paste is sent to a server.

Reading someone else's regex

A regex in a codebase rarely comes with a comment, and the hard part is usually the nesting: which quantifier applies to which group, and where an alternation starts and ends. Breaking it into one row per token makes that visible. To see what it actually matches, run it on real input in the regex tester.

Flavours differ at the edges

The syntax explained here is shared by JavaScript and PCRE, which PHP's preg functions use. Possessive quantifiers such as a++ and named groups written (?P<name>) are PCRE only, and lookbehind needs a modern engine. Python's re module is close but has its own differences, listed in the re documentation.

Share

Frequently asked questions

What does ?: mean in a regex?
It makes a non-capturing group: (?:abc) groups the letters so a quantifier or alternation applies to all of them, without storing the match as $1.
What is the difference between .* and .*?
.* is greedy and takes as much as it can before backtracking; .*? is lazy and takes as little as possible. Between two quotes, ".*" spans to the last quote on the line and ".*?" stops at the next one.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools