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
| Pattern | Description | Example |
|---|---|---|
. | Any character except newline | a.c matches "abc", "a1c" |
\d | Any digit (0-9) | \d{3} matches "123" |
\D | Any non-digit | \D+ matches "abc" |
\w | Word character (a-z, A-Z, 0-9, _) | \w+ matches "hello_123" |
\W | Non-word character | \W matches "!", " " |
\s | Whitespace (space, tab, newline) | \s+ matches spaces |
\S | Non-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 |
| Pattern | Description | Example |
|---|---|---|
* | 0 or more | a* matches "", "a", "aaa" |
+ | 1 or more | a+ 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 |
| Pattern | Description | Example |
|---|---|---|
(abc) | Capturing group | (ab)+ matches "abab" |
(?:abc) | Non-capturing group | Groups without capturing |
(?<name>abc) | Named capture group | (?<year>\d{4}) |
\1 | Backreference to group 1 | (\w+)\s+\1 matches repeated words |
a|b | a 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 "$" |
| Pattern | Description | Example |
|---|---|---|
^ | Start of string/line | ^Hello matches at start |
$ | End of string/line | world$ matches at end |
\b | Word boundary | \bcat\b matches whole word "cat" |
\B | Non-word boundary | \Bcat matches "cat" in "scatter" |
\A | Absolute start of string | Never after newline |
\Z | Absolute end of string | Never before newline |
| Flag | Name | Description |
|---|---|---|
g | Global | Find all matches, not just the first |
i | Case Insensitive | Match both uppercase and lowercase |
m | Multiline | ^ and $ match start/end of each line |
s | Dotall | . matches newline characters too |
u | Unicode | Enable full Unicode support |
y | Sticky | Match at exact position in string |
How to Use This Tool
- 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.
- Click Explain Regex: The tool breaks down each component of your pattern into plain English, showing what each character, group, and quantifier matches.
- Review the Breakdown: The pattern breakdown shows each token separately with its meaning. Complex patterns become understandable when decomposed into individual parts.
- 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.