Regex Tester

Test and debug regular expressions visually

Pattern & Setup
/ /

Matches & Info
Match Preview
Results will appear here...
Detailed Matches
No matches yet.

Mastering Regular Expressions: A Visual Guide

The Developer's Superpower

Regular Expressions (Regex) are often seen as a dark art. A string of cryptic characters like ^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ can look intimidating. But once you understand them, they become arguably the most powerful tool in your text-processing arsenal.

Whether you are validating user forms, scraping data from websites, or doing complex find-and-replace operations in your code editor, Regex saves you hours of manual work. It allows you to define a "pattern" of text, and then instantly find every piece of text that matches that pattern.

Our Regex Tester is built to be your sandbox. It gives you immediate, visual feedback. You don't have to guess if your pattern works—you can see the matches highlight in real-time as you type.

How to Use This Tool

This tool is designed for speed and clarity. Here is your workflow:

  1. Enter Your Pattern: Type your regex in the top input. e.g., \d{3} to find 3 digits.
  2. Set Your Flags: The little box next to the pattern controls the "mode".
    • g (Global): Find all matches, not just the first one.
    • m (Multi-line): Allows ^ and $ to match the start/end of each line, not just the whole string.
    • i (Case Insensitive): Makes a match both "a" and "A".
  3. Test Your String: Paste your text content in the large text area.
  4. Analyze Results: Look at the "Match Preview" to see the highlighting. Check "Detailed Matches" to see Capture Groups (parts of the match you want to extract).

Core Concepts Crash Course

You can build 90% of regex patterns knowing just these four concepts:

1. Character Classes

These tell the engine "Match a specific type of character".

  • \d: Any digit (0-9).
  • \w: Any word character (letters, numbers, underscores).
  • \s: Any whitespace (space, tab, newline).
  • .: Any character at all (except newlines).

2. Quantifiers

These ask "How many times?"

  • +: One or more times. \d+ matches "1" and "12345".
  • *: Zero or more times.
  • ?: Zero or one time (Optional).
  • {3}: Exactly 3 times.

3. Anchors

These match a position, not a character.

  • ^: Start of the string.
  • $: End of the string.

4. Groups

Wrapping part of your regex in parentheses (...) creates a "Capture Group". This is useful if you want to match a full date like "2023-12-25" but extract just the year "2023".

Common Useful Patterns

Here are some "recipes" you can copy and paste:

  • Email Address:
    [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}
    Matches standard emails like user@example.com
  • Standard Date (YYYY-MM-DD):
    \d{4}-\d{2}-\d{2}
  • Hex Color Code:
    #?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})
  • Strong Password:
    ^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$
    Minimum 8 characters, at least one letter and one number.

Performance Hazard: Catastrophic Backtracking

Be careful with nested quantifiers like (a+)+. If you run this against a long string of "aaaaa" that almost matches but fails at the end, the engine tries every single combination of grouping. This can freeze your browser or crash your server. Always try to be specific!

Frequently Asked Questions

What does the `?` mean after a quantifier (e.g., `*?`)?

That makes the quantifier "Lazy". By default, regex is "Greedy"—it tries to match as much as possible. If you have `<div>...</div>` and use `<.*>`, it typically matches the whole string. Using `<.*?>` stops at the first closing bracket.

How do I match a literal `.` or `?`?

You need to "escape" it with a backslash. Use \. to match a real dot, and \? to match a real question mark.

What is a "Lookahead"?

A lookahead (?=...) asserts that what follows matches the pattern, but it doesn't consume it (it doesn't become part of the match result). It's great for validation, like checking if a password contains a number without "using up" the characters.

Why isn't my regex working in Python/C#?

This tool uses the JavaScript regex engine. While most regex syntax is standard, some advanced features (like Lookbehinds or specific named groups) vary slightly between languages like Python, Java, and .NET.

Can I use regex to parse HTML?

You can, but you usually shouldn't. HTML is nested and complex. Regex is linear. For extracting simple tags, it's fine. For parsing a whole document, use a proper HTML parser (like DOMParser in JS or BeautifulSoup in Python) to avoid headaches.

What are "Flags"?

Flags capture global settings for the engine. `g` (global), `i` (insensitive), and `m` (multiline) are the big three. There is also `s` (dotAll), which allows the dot . to match newlines.