Regex Tester

Test and debug regular expressions

//

What is Regex Tester?

Regular expressions define search patterns using a concise syntax of metacharacters, quantifiers, and character classes. They are the standard tool for validating input formats, extracting structured data from text, and performing find-and-replace operations across virtually every programming language. This tester lets you write a pattern, apply it to sample text, and instantly see which parts match — with visual highlighting and a clear list of captured results.

How to Use

  1. Enter your regex pattern in the pattern field (without surrounding slashes).
  2. Toggle the flags you need: g (global, find all matches), i (case-insensitive), m (multiline).
  3. Paste or type the text you want to test against in the test text area.
  4. Click Test to execute the regex — matches are highlighted directly in the text.
  5. Review the matches list below the highlighted output to see each captured result.
  6. Press Load Sample to try a pre-built email-matching pattern with sample text.

Why Use This Tool?

Instant visual highlighting of matches directly in the source text
Support for all standard regex flags — global, case-insensitive, and multiline
Clear error messages when a pattern has invalid syntax
Match count and individual match display make it easy to verify pattern correctness
Learn regex interactively by experimenting with patterns and seeing results in real time
Debug complex patterns before committing them to production code

Tips & Best Practices

  • Start simple: patterns like \d+ (digits) or \w+ (word characters) are easy to understand and build upon
  • Use anchors ^ and $ to match the start or end of a line or the entire string
  • Escape special characters with a backslash: \., \*, \?, \+, \|, \(, \)
  • Character classes like [a-z] or [0-9] define ranges of characters to match
  • Quantifiers control repetition: * (zero or more), + (one or more), ? (zero or one), {n,m} (between n and m)
  • Parentheses () create capture groups that let you extract specific parts of a match

Frequently Asked Questions

What are the most commonly used regex patterns?

Frequently used building blocks include \d+ for one or more digits, \w+ for word characters, [a-zA-Z]+ for letters only, \s+ for whitespace, \b for word boundaries, .+ for any characters, and \b\w+@\w+\.\w+\b for a basic email check. These primitives combine into more complex patterns for URLs, phone numbers, and custom formats.

What do the regex flags g, i, and m do?

The g (global) flag finds every match in the text rather than stopping at the first one. The i (case-insensitive) flag matches regardless of uppercase or lowercase differences. The m (multiline) flag makes ^ and $ match at the beginning and end of each line instead of the entire string. Flags can be combined — for example, gi finds all case-insensitive matches.

Why is my regex not matching?

Common causes include: forgetting to escape special characters (a literal dot needs \. not .), incorrect anchors (^$ vs \b for word boundaries), the wrong flag settings (especially case sensitivity), typos in the pattern, or the pattern being more restrictive than intended. Test each part of your pattern incrementally to isolate the issue.

When should I NOT use regex?

Avoid regex for parsing nested or recursive structures like HTML, XML, or balanced parentheses — use a proper parser instead. Regex is also a poor fit for context-sensitive validation like date range checking (use date libraries) or complex business rules. If your regex grows beyond a few dozen characters, consider whether a different approach would be clearer and more maintainable.

Is my test text kept private?

Yes. All regex compilation and matching runs entirely in your browser using the built-in JavaScript RegExp engine. Your pattern and test text are never sent to any server, API, or third-party service.

How do I capture parts of a match?

Use parentheses () to create capture groups. For example, (\d+)-(\d+)-(\d+) creates three groups that each capture a number separated by dashes. In JavaScript, access them via match[1], match[2], match[3]. In Python, use re.search().group(1), group(2), group(3). Non-capturing groups (?:...) group without capturing.

Real-world Examples

Validating a Date Format in Form Input

Use the pattern ^\d{4}-\d{2}-\d{2}$ with the multiline flag to verify that each line of input matches the YYYY-MM-DD date format before processing.

Input
2024-01-15
2024-13-99
hello
Output
Match: "2024-01-15" — the other lines do not match the date pattern

Extracting All Email Addresses from a Log

Use the pattern \b\w+@\w+\.\w+\b with the global flag to find and extract every email address from a server log or text document.

Input
Contact [email protected] or [email protected] for help.

Related Tools