Regex Explainer

Regex Explainer

Enter a regular expression to get a plain English explanation of each component.

/ /

Explanation

Enter a regex pattern and click "Explain Regex"

Pattern Breakdown

Regex Quick Reference

PatternDescriptionExample
.Any character except newlinea.c matches "abc", "a1c"
\dAny digit (0-9)\d{3} matches "123"
\DAny non-digit\D+ matches "abc"
\wWord character (a-z, A-Z, 0-9, _)\w+ matches "hello_123"
\WNon-word character\W matches "!", " "
\sWhitespace (space, tab, newline)\s+ matches spaces
\SNon-whitespace\S+ matches words
[abc]Any of a, b, or c[aeiou] matches vowels
[^abc]Not a, b, or c[^0-9] matches non-digits
[a-z]Range from a to z[A-Za-z] matches letters
PatternDescriptionExample
*0 or morea* matches "", "a", "aaa"
+1 or morea+ matches "a", "aaa"
?0 or 1 (optional)colou?r matches "color", "colour"
{n}Exactly n times\d{4} matches "2024"
{n,}n or more times\d{2,} matches "12", "123"
{n,m}Between n and m times\d{2,4} matches "12", "1234"
*?0 or more (lazy)Matches as few as possible
+?1 or more (lazy)Matches as few as possible
PatternDescriptionExample
(abc)Capturing group(ab)+ matches "abab"
(?:abc)Non-capturing groupGroups without capturing
(?<name>abc)Named capture group(?<year>\d{4})
\1Backreference to group 1(\w+)\s+\1 matches repeated words
a|ba or b (alternation)cat|dog matches either
(?=abc)Positive lookahead\d(?=px) matches digit before "px"
(?!abc)Negative lookahead\d(?!px) matches digit not before "px"
(?<=abc)Positive lookbehind(?<=\$)\d+ matches number after "$"
PatternDescriptionExample
^Start of string/line^Hello matches at start
$End of string/lineworld$ matches at end
\bWord boundary\bcat\b matches whole word "cat"
\BNon-word boundary\Bcat matches "cat" in "scatter"
\AAbsolute start of stringNever after newline
\ZAbsolute end of stringNever before newline
FlagNameDescription
gGlobalFind all matches, not just the first
iCase InsensitiveMatch both uppercase and lowercase
mMultiline^ and $ match start/end of each line
sDotall. matches newline characters too
uUnicodeEnable full Unicode support
yStickyMatch at exact position in string
Horizontal Banner (Responsive) 728x90 / 320x100

How to Use This Tool

  1. Enter Your Regex: Paste or type a regular expression pattern between the slashes. Include any flags (g, i, m, s, u) in the flags field. The pattern is parsed as you type.
  2. Click Explain Regex: The tool breaks down each component of your pattern into plain English, showing what each character, group, and quantifier matches.
  3. Review the Breakdown: The pattern breakdown shows each token separately with its meaning. Complex patterns become understandable when decomposed into individual parts.
  4. Use the Quick Reference: The tabs below provide a reference for regex syntax—characters, quantifiers, groups, anchors, and flags. Use this while learning or constructing patterns.

Technical Details

Regular expressions are patterns that describe sets of strings using a formal syntax. The pattern is processed left-to-right, with each token matching specific characters or positions. Character classes ([a-z]) match single characters from a set. Quantifiers (*, +, ?, {n,m}) specify repetition. Anchors (^, $, \b) match positions rather than characters. Groups ((...)) capture substrings for extraction or backreferences.

This explainer parses the regex into tokens and provides human-readable descriptions. It handles escaped characters (\d, \w, \s), lookahead/lookbehind assertions, non-capturing groups, and nested constructs. Regex syntax varies slightly between engines (JavaScript, PCRE, Python re). This tool uses JavaScript regex syntax, which most modern languages support. Complex patterns can be understood by reading the explanation from top to bottom, matching the left-to-right evaluation of the regex engine.

Common Mistakes to Avoid

  • Forgetting to Escape Special Characters: Characters like . * + ? [ ] ( ) { } ^ $ | \ have special meaning. To match them literally, escape with backslash: \. matches a period, \( matches an opening parenthesis. Unescaped, they change pattern behavior.
  • Greedy vs. Lazy Quantifiers: By default, *, +, and ? are greedy—they match as much as possible. This causes ".*" to consume more than expected. Use *?, +?, or ?? for lazy (minimal) matching when you need the shortest match.
  • Misunderstanding Character Classes: Inside [...], most special characters lose their meaning. [.] matches a literal dot, no escape needed. But ^ at the start negates the class, and - creates ranges. Place - at the end or escape it to match literally.

Related Tools

Want to build a regex without writing the pattern manually? Use our Regex Generator to create patterns from common use cases. For pre-built, tested patterns, browse the Regex Pattern Library.

Frequently Asked Questions

What does the g flag do?

The global (g) flag finds all matches in the string, not just the first. Without g, matching stops after the first match. With g, the engine continues searching from where the last match ended, returning all occurrences.

What's the difference between .* and .*?

Both match any characters. .* is greedy—it matches as many characters as possible. .*? is lazy—it matches as few as possible. In "<b>bold</b>", .*?< stops at the first <, while .*< matches to the last <.

How do lookahead and lookbehind work?

Lookahead (?=...) and lookbehind (?<=...) are zero-width assertions—they check if a pattern exists without including it in the match. (?=@) matches a position followed by @, but @ isn't captured. Negative versions (?!...) and (?<!...) check for pattern absence.