Regex Live Visual Flowcharter

Input any regular expression. The parser builds an interactive SVG flowchart showing each capture group step-by-step.

Plain English Explainer
AST Visual Flowchart
Live Match Results

How The Regex Engine Works

Regular Expressions (RegExp) are sequences of characters that define a search pattern. They are the backbone of text processing, validation, and scraping in almost every programming language.

Our Advanced Regex Tool solves the biggest problem with Regex: readability. By parsing your string into an Abstract Syntax Tree (AST), we visually decouple the complex nested logic into a flowchart. Furthermore, our engine generates a Plain English explanation, translating the cryptic symbols into a step-by-step readable guide.

Regex Operator Cheat Sheet

Use this reference table to understand the core tokens available in most modern regex engines:

SyntaxNameDescription
[abc]Character ClassMatches exactly one character that is either a, b, or c.
[^abc]Negated ClassMatches exactly one character that is NOT a, b, or c.
*Star QuantifierMatches the preceding token 0 or more times.
+Plus QuantifierMatches the preceding token 1 or more times.
?Optional QuantifierMatches the preceding token 0 or 1 time (makes it optional).
{n,m}Range QuantifierMatches the preceding token between n and m times.
^Start AnchorMatches the absolute beginning of the string.
$End AnchorMatches the absolute end of the string.
\dDigit EscapeMatches any number (equivalent to [0-9]).
\wWord EscapeMatches any letter, number, or underscore.

Mastering Lookarounds (Zero-Length Assertions)

Lookarounds are advanced assertions that tell the regex engine to look ahead (or behind) the current position in the string, but they do not consume characters. This means they check for a condition without actually including the matched text in the final result.

  • (?=...) Positive Lookahead: Asserts that what immediately follows the current position is the pattern inside the lookahead. Used heavily in password validation (e.g., (?=.*\d) asserts the string contains a number somewhere).
  • (?!...) Negative Lookahead: Asserts that what immediately follows is not the pattern.
  • (?<=...) Positive Lookbehind: Asserts that what immediately precedes the current position is the pattern.
  • (?<!...) Negative Lookbehind: Asserts that what immediately precedes is not the pattern.

The Danger of Catastrophic Backtracking

If you write a regular expression with nested quantifiers (e.g., (a+)+) and apply it to a long string that almost matches but fails at the very end, you will experience Catastrophic Backtracking.

ReDoS (Regular Expression Denial of Service)

When a regex fails, the engine steps backward and tries every possible permutation of the quantifiers. With (a+)+, a string of 30 'a's followed by an 'x' will cause the engine to evaluate over 1 billion combinations before finally failing. This causes the server CPU to spike to 100% and freeze, a vulnerability known as ReDoS. Always avoid nesting quantifiers like + or * inside groups that also have quantifiers.

JavaScript vs PCRE Engines

  • Lookbehinds: Historically, JavaScript (V8) did not support lookbehinds like (?<=foo). While modern browsers now support them, legacy environments will throw a syntax error. PCRE (PHP/Perl) has supported them for decades.
  • Atomic Groups: JavaScript does not support atomic groups (?>...) or possessive quantifiers ++ which are crucial for preventing catastrophic backtracking. PCRE supports both natively.

Frequently Asked Questions

ReDoS (Regular Expression Denial of Service)

What is Catastrophic Backtracking in Regex?

Catastrophic backtracking occurs when a regular expression contains nested quantifiers (like (a+)+) or overlapping alternations. If the engine fails to find a match at the end of the string, it steps backward and tries every possible combination. This can cause the engine to take exponentially longer to fail, completely freezing your application or server.

How do I make a capture group non-capturing?

Add ?: at the very beginning of your group. For example, (?:abc) will group the letters together for quantifiers without saving the match into memory, drastically improving parser performance.

What does \b do in a regular expression?

\b is a word boundary anchor. It matches the invisible position where a word character (like a letter or number) sits directly next to a non-word character (like a space or punctuation). It doesn't consume any characters itself.

What is the difference between a Lookahead and a Lookbehind?

A Lookahead (?=foo) asserts that what immediately follows the current position is "foo", while a Lookbehind (?<=foo) asserts that what immediately precedes the current position is "foo". Neither of them consume characters, they merely assert conditions.

Why is my regex matching too much text?

Your quantifier is likely "greedy" by default. If you use .*, the engine will match as much text as possible until the end of the string, and then backtrack. To make it "lazy" so it stops at the first occurrence, append a question mark: .*?.

Rate Regex Live Visual Flowcharter

Help us improve by rating this tool.

4.7/5
777 reviews