Regex Tester

Test and debug Regular Expressions in real-time. Visualize matches, capture groups, and understand your patterns with our secure playground.

//
Contact us at support@moderncalcs.com or info@example.org
Total Matches
2
Capture Groups
2
Pattern Size
50

Pattern Explanation

.Any character except newline
+One or more of the preceding
(...)Capturing group
[...]Character set (any of these)

Match Groups (Last Match)

Full Match
info@example.org
Group 1
info
Group 2
example.org

Regex Testing Simplified

Regular Expressions are powerful but notoriously difficult to read. Our Regex Tester helps you bridge that gap by providing a visual breakdown of your matches and an auto-generated explanation of the tokens you use.

Common Regex Use Cases

  • Form Validation: Checking if an input is a valid email, phone number, or strong password.
  • Data Extraction: Scraping URLs, dates, or prices from a large block of unstructured text.
  • Search & Replace: Performing complex text transformations that standard "Find" cannot handle.

Regex Tester: Mastering the Language of Pattern Matching

Regular Expressions (Regex) are one of the most powerful yet intimidating tools in a developer's arsenal. From validating email addresses to scraping data from logs, Regex allows you to find "needles in haystacks" with incredible precision. Our Regex Tester provides a real-time, interactive environment to build and debug your patterns safely before you commit them to your code.

Formula
/pattern/flags

Example: /[a-z0-9]/gi matches all letters and numbers regardless of case.

The Core Syntax: Literals and Metacharacters

Regex is built from two types of characters: 1) Literals: Characters that match themselves (e.g., 'abc' matches 'abc'). 2) Metacharacters: Special symbols like `.` (any character), `^` (start of line), and `$` (end of line) that give Regex its 'magic'. Mastering the combination of these two is what allows you to describe complex patterns like 'a string that starts with a capital letter and ends with three digits'.

Quantifiers: Controlling the Match Count

Quantifiers tell the engine how many times a character or group should repeat. `*` means zero or more, `+` means one or more, and `?` means zero or one. You can also be specific with curly braces: `{3}` means exactly three times, while `{2,5}` means between two and five times. These are essential for validating inputs like Phone Numbers where the number of digits is fixed.

Character Classes and Ranges

Instead of listing every possibility, you can use Character Classes. `[a-z]` matches any lowercase letter, `[0-9]` matches any digit, and `\s` matches any whitespace. Shorthands like `\w` (word character) and `\d` (digit) make your patterns much shorter and easier to read. Our tester highlights these different elements in your pattern to help you visualize the logic.

Grouping and Backreferences

By wrapping part of your pattern in parentheses `( )`, you create a Capture Group. This allows you to treat a block as a single unit or extract it later for replacement. Advanced users use backreferences (like `\1`) to match the exact same text that was captured earlier, which is useful for finding duplicate words or matching closing HTML tags perfectly.

Practical Examples

Email Validation Pattern

A standard pattern for checking email format.

  • 1.Pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
  • 2.Input: test@example.com (Match!)
  • 3.Input: invalid-email (No Match)
  • 4.Insight: Anchors (^ and $) ensure the whole string is an email, not just a part of it.

Extracting Prices

Finding currency amounts in a block of text.

  • 1.Pattern: \$\d+(?:\.\d{2})?
  • 2.Input: 'The total is $45.99 and tax is $3.00'
  • 3.Result: Highlights $45.99 and $3.00.
  • 4.Insight: The optional group (?:...) handles cents if they exist.

Regex Cheat Sheet (Common Symbols)

  • . (Dot): Matches any single character except newline.
  • \d: Matches any digit (0-9).
  • \w: Matches any word character (alphanumeric + underscore).
  • \s: Matches any whitespace character.
  • [abc]: Matches any character inside the brackets.
  • [^abc]: Matches any character NOT inside the brackets.

Developer Tips for Better Regex

  • Keep it Simple: If a string split or index check works, use that instead of a complex regex.
  • Comment Your Patterns: Use the 'x' flag or comments to explain what each part does.
  • Avoid ReDoS: Be careful with nested quantifiers (like (a+)+) which can cause performance hangs.
  • Test Boundary Cases: Always test with empty strings, very long strings, and special symbols.
  • Use Anchors: Use ^ and $ to prevent accidental matches in the middle of a string.

Frequently Asked Questions

What is Regex?

Regex (Regular Expression) is a sequence of characters that forms a search pattern. It's used for string matching, searching, and manipulation in almost all programming languages.

How to test Regex in my browser?

Enter your pattern in the regex box and your sample text in the test box. Our tool will instantly highlight all matches within the text.

What are Regex flags?

Flags modify how the search is performed. Common flags include 'g' (global - find all matches), 'i' (case-insensitive), and 'm' (multiline).

What is a 'Capture Group'?

Parentheses ( ) are used to create groups. They allow you to extract specific parts of a match for further processing.

What is the difference between .* and .*?

'.*' is 'greedy' and matches as much as possible. '.*?' is 'lazy' and matches the minimum amount needed to satisfy the pattern.

How to escape special characters in Regex?

Use a backslash (\) before a special character (e.g., \. to match a literal period or \( to match a literal parenthesis).

What are 'Lookaheads'?

Lookaheads (?=...) allow you to match a pattern only if it is followed (or not followed) by another specific pattern, without including the second pattern in the match.

Is Regex the same in all languages?

The core syntax is similar, but there are different 'flavors' (JavaScript, PHP, Python, PCRE). Our tool uses the JavaScript (ECMAScript) regex engine.

Can Regex be used for validation?

Yes. It is the standard way to validate inputs like emails, phone numbers, and zip codes on both the frontend and backend.

Is this tool safe for testing private data?

Yes. The regex processing happens entirely in your browser using the local JavaScript engine. No data is sent to our servers.