Regex Tester

Test, debug, and master regular expressions.

//
0 Matches
Hello World 123. This is a test string for regex matching. Email: test@example.com
No matches found

The Ultimate Regular Expression Debugger

Regular Expressions (Regex) are one of the most powerful yet misunderstood tools in a developer's arsenal. They allow you to define complex search patterns to validate input, extract data, or manipulate strings with surgical precision.

Our Pro Regex Tester is designed to demystify this syntax. Unlike a black-box validator, our tool visualizes exactly what your pattern is matching and why. With features like real-time highlighting, group inspection, and substitution testing, you can debug even the most catastrophic backtracks before they reach production.

Deep Dive: Understanding Regex Syntax

Anchors & Boundaries

These don't match characters, but positions in the text.

  • ^ : Start of string (or line with m flag).
  • $ : End of string (or line with m flag).
  • \b : Word boundary (between word/non-word chars).

Character Classes

Shorthands for common sets of characters.

  • \d : Any digit (0-9).
  • \w : Any word char (Alphanumeric + underscore).
  • \s : Any whitespace (space, tab, newline).
  • . : (Dot) Any character except newline.

Quantifiers

Determine how many times the previous element repeats.

  • * : 0 or more times.
  • + : 1 or more times.
  • ? : 0 or 1 time (Optional).
  • {3} : Exactly 3 times.

Groups & Logic

Combine patterns and capture data.

  • (...) : Capturing group.
  • (?:...) : Non-capturing group.
  • a|b : OR operator (match a OR b).
  • [abc] : Character set (any of a, b, c).

Advanced Concepts: Lookarounds

Lookarounds allow you to match a pattern only if it's followed by (lookahead) or preceded by (lookbehind) another pattern—without including that second pattern in the match result.

  • Positive Lookahead (?=...): Match only if followed by...
  • Negative Lookahead (?!...): Match only if NOT followed by...
  • Positive Lookbehind (?<=...): Match only if preceded by...
  • Negative Lookbehind (?<!...): Match only if NOT preceded by...

Common Use Cases

Input Validation: Ensuring user emails, passwords, and phone numbers meet strict formats before sending data to the server.
Data Scraping: Extracting specific information (like prices, dates, or IDs) from large, unstructured text blocks or HTML.
Find & Replace: Bulk editing code or text, such as converting `YYYY-MM-DD` dates to `DD/MM/YYYY` format using capture groups.

Frequently Asked Questions

Frequently Asked Questions

What regex engine does this use?

This tool uses the native JavaScript RegExp engine running in your browser. This means the behavior (including lookaheads and unicode support) will match exactly what you see in Node.js or modern web browsers like Chrome and Firefox.

What do the flags (g, i, m) mean?

Flags change how the engine parses the pattern: g (Global): Find all matches, not just the first one. i (Insensitive): Ignore case (matches 'A' and 'a'). m (Multiline): The ^ and $ anchors match the start/end of each line, not just the whole string. s (DotAll): Allows the dot (.) to match newline characters.

How do I match a specific number of digits?

Use curly braces {} aka Quantifiers. For example, \d{3} matches exactly 3 digits. \d{2,4} matches between 2 and 4 digits. \d{3,} matches 3 or more digits.

What is the difference between .* and .*?

.* is Greedy—it matches as much text as possible (eating everything until the last match). .*? is Lazy (or non-greedy)—it matches as little as possible. This is crucial when parsing HTML tags or quoted strings to stop at the first closing delimiter.

Does this support lookbehinds?

Yes! Modern browsers support lookbehinds (e.g., (?<=foo)bar). Since this tool runs in your browser, if your browser supports it (Chrome 62+, Firefox 78+, Safari 16.4+), we support it.

Can I use this for PHP or Python regex?

Mostly yes. The core syntax (character classes, quantifiers, groups) is standard across languages (PCRE-flavor). However, JavaScript Regex has some minor differences, such as lacking the x (extended) flag or support for atomic groups (without plugins).

How do I capitalize the first letter of each word?

You can match \b\w (first character of a word). In the Substitution tab, JavaScript supports case transformation in replacement strings using functions, but for standard regex replacement, you might need to use programmatic approaches or complex capture groups.

What is Catastrophic Backtracking?

It's a performance issue where a poorly written regex (like (a+)+b) takes exponential time to fail on a non-matching string. Our tool attempts to detect infinite loops, but always optimize your patterns for production!

How do I capture data?

Use Parentheses (). Anything inside () is a capture group. You can reference it in the result as Group 1, Group 2, etc., or in a replacement string as $1, $2.

Is my data private?

Yes. All processing happens 100% locally in your browser. No text or patterns are sent to any server.

What are Named Capture Groups?

Instead of numbered groups $1, you can name them using (?<name>...). You can then reference them in replacements using $<name>. This makes complex patterns much more readable.

How to match a literal special character?

If you want to match a character that has special meaning in regex (like ., *, ?, +, [, ], (, )), you must escape it with a backslash. E.g., to match a dot, use \.. To match a question mark, use \?.