Regex Tester

Does your regex pattern match the right text?

Test regular expressions against sample text with instant feedback. See matches, capture groups, and validation results in real-time to debug and perfect your regex patterns before deploying to production code.

Updated June 2026 · How this works

Example calculation — edit any field to use your own numbers

Worth knowing
How It Works
The formula, explained simply

Regular expressions work like a search template that describes text patterns rather than exact strings. Instead of searching for 'john@email.com', you create a pattern that matches any email format: letters and numbers, followed by @, followed by a domain structure. The regex engine reads your pattern character by character, trying to match it against every position in your text.

The power comes from special characters that represent categories rather than literals. \d means 'any digit' instead of literally 'd', while + means 'one or more of the previous character'. When you write \d+, you're telling the engine to match one or more consecutive digits, which could be '7' or '42' or '999999'.

Capture groups add another layer by letting you extract specific parts of matches. Parentheses around parts of your pattern tell the engine 'remember what matched here'. This turns regex from a simple yes-no matcher into a data extraction tool that can pull structured information from unstructured text.

When To Use This
Right tool, right situation

Use regex testing when you need to validate input format before processing, like checking email addresses, phone numbers, or account IDs. Testing is essential when extracting structured data from logs, CSV files, or API responses where the format is predictable but not perfectly consistent. It's also valuable for search and replace operations where you need to transform text systematically.

Don't use regex for parsing nested structures like HTML, XML, or JSON - these require proper parsers that understand the hierarchical nature of the data. Regex also isn't appropriate for complex validation that requires business logic, like checking if an email address actually exists or if a credit card number passes the Luhn algorithm.

Avoid regex when simple string methods would work just as well. Searching for a literal string doesn't need regex complexity, and string.includes() or string.indexOf() will be faster and clearer. Similarly, splitting on a simple delimiter doesn't need regex unless you're handling multiple delimiter types or whitespace variations.

Common Mistakes
Why results sometimes look wrong

The biggest mistake is not escaping special characters when you want them literally. A dot . matches any character, not just periods, so use \. when you need an actual dot. Similarly, + means 'one or more' but \+ matches a literal plus sign. This escaping confusion leads to patterns that seem to work in simple tests but fail in production with unexpected characters.

Another common error is forgetting the global flag when you want all matches. Without 'g', regex stops after finding the first match, which can make your pattern appear broken when testing against text with multiple valid matches. The related mistake is using global regex in a loop without resetting - the regex object maintains state between exec() calls.

Overcomplicating patterns with too many features creates maintenance nightmares and performance problems. A simple pattern that works for 95% of cases is usually better than a complex one that handles every edge case perfectly. Complex patterns are harder to debug, slower to execute, and more likely to have subtle bugs that only surface with unusual input data.

The Math
Worked examples and deeper derivation

Regex engines use finite state automata - mathematical machines that process input one character at a time and transition between states based on what they see. Your pattern gets compiled into a state machine where each state represents a position in the match process. The engine starts in the initial state and follows transitions based on the input characters.

Quantifiers like *, +, and {n,m} create loops in the state machine that can match varying amounts of input. The engine uses backtracking when multiple paths are possible, trying one route and backing up to try alternatives if the first path fails. This backtracking can cause exponential time complexity in pathological cases, which is why some patterns can freeze your browser.

Greedy vs lazy quantifiers control how much text the engine consumes. .* matches as much as possible (greedy), while .*? matches as little as possible (lazy). Understanding this difference prevents common bugs where patterns match too much text, like matching from the first quote to the last quote in a line instead of matching individual quoted strings.

Validating email addresses in user registration
Pattern: \b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b, Test text: 'user@domain.com, invalid@, @missing.com', Flags: g
Found 1 match out of 3 email-like strings. The pattern correctly identified only the valid email format, helping you catch malformed addresses before they enter your database.
Extracting phone numbers from customer data
Pattern: \(?\d{3}\)?[-.\ ]?\d{3}[-.\ ]?\d{4}, Test text: 'Call (555) 123-4567 or 555.987.6543', Flags: g
Found 2 matches with different formatting. This flexible pattern handles parentheses, dashes, dots, and spaces, ensuring you capture phone numbers regardless of how customers enter them.
Parsing log files for error codes
Pattern: ERROR\s+(\d{3,4}):\s+(.+), Test text: 'INFO: System started\nERROR 404: Page not found\nERROR 500: Database timeout', Flags: gm
Found 2 matches with capture groups. The parentheses create groups that extract both the error code (404, 500) and the message, making it easy to categorize and count different error types in your logs.
Expert Unlock
The thing most explanations skip

Most developers don't realize that regex engines can differ significantly in features and performance characteristics. JavaScript uses a backtracking NFA engine that supports lookaheads and captures but can hang on certain patterns. Understanding your engine's limitations helps you write patterns that are both correct and efficient in your specific environment.

How do I fix common regex testing problems?

Why does my regex pattern show no matches when I expect it to work?
The most common cause is escaping issues - backslashes need to be doubled in many contexts. Try testing without flags first, then add the global flag to find multiple matches. Case sensitivity also trips up many patterns, so consider adding the 'i' flag to ignore case differences.
What regex flags should I use for finding all matches in text?
Use 'g' for global matching to find all occurrences, not just the first one. Add 'i' to ignore case if your pattern should match both uppercase and lowercase. The 'm' flag treats each line as separate for ^ and $ anchors, useful for multi-line text parsing.
How do I capture specific parts of my regex matches?
Use parentheses to create capture groups around the parts you want to extract. For example, (\d{3})-(\d{3})-(\d{4}) captures area code, prefix, and number separately. Non-capturing groups (?:...) group without capturing if you only need the grouping for operators like * or +.

Need something this doesn't cover?

Suggest a tool — we'll build it →