Regex Tester - Test Regular Expressions Online
How to Use the Regex Tester
Enter your regular expression pattern in the top field, select your flags (g for global, i for case-insensitive, m for multiline), then type or paste a test string in the text area below. Matches are highlighted in real time as you type. A results table shows each match with its index position, matched text, and any capture group values.
Understanding Regular Expressions
Regular expressions (regex) are patterns that describe sets of strings. They are one of the most powerful tools in a developer’s toolkit, used for validation, search, text extraction, and data transformation across virtually every programming language.
Despite their power, regex patterns can be difficult to write correctly. A small mistake in the pattern can cause it to match too much, too little, or nothing at all. This tester gives you instant visual feedback so you can iterate on your pattern without running code or writing test scripts.
Common Regex Patterns
Here are frequently needed patterns that developers search for regularly:
| Pattern | Matches | Example |
|---|---|---|
^\S+@\S+\.\S+$ | Email (basic) | user@example.com |
^https?:// | URL protocol | https://example.com |
\b\d{3}-\d{3}-\d{4}\b | US phone | 555-123-4567 |
^\d{4}-\d{2}-\d{2}$ | ISO date | 2026-04-06 |
^#?([0-9a-fA-F]{6})$ | Hex color | #2563eb |
\b\d{1,3}(\.\d{1,3}){3}\b | IPv4 address | 192.168.1.1 |
Regex Flags Explained
Flags modify how the regex engine processes your pattern. Choosing the right flags is as important as writing the pattern itself.
The global (g) flag is needed when you want to find all occurrences in the text, not just the first match. The case-insensitive (i) flag is useful for matching text regardless of capitalization, such as finding “Error”, “error”, and “ERROR” with a single pattern. The multiline (m) flag changes the behavior of ^ and $ so they match line boundaries rather than the start and end of the entire string.
Debugging Regex Patterns
When your pattern does not match as expected, start by simplifying it. Remove parts of the pattern until it matches, then add complexity back gradually. Check for common mistakes like unescaped special characters (dots, brackets, parentheses), incorrect quantifiers, and missing anchors.
Greedy vs. lazy quantifiers are a frequent source of bugs. By default, * and + are greedy and match as much text as possible. Adding ? makes them lazy, matching as little as possible. For example, <.*> matches from the first < to the last > in the string, while <.*?> matches individual tags.
Using Capture Groups for Data Extraction
Capture groups let you extract specific portions of matched text. They are essential for parsing structured data like log files, CSV rows, and configuration values. Named capture groups using (?<name>pattern) make your regex more readable and your code easier to maintain.
This tool displays capture group values in the results table, so you can verify that each group captures exactly the text you expect before using the pattern in your application code.
For testing patterns against structured data, you may also find the Base64 Encoder useful when working with encoded strings, or the URL Encoder when building patterns for URL validation.
Related Tools
- Text Diff Checker - Compare text before and after regex replacements
- Base64 Encoder/Decoder - Encode and decode Base64 strings
- URL Encoder/Decoder - Encode special characters in URLs
Frequently Asked Questions
How do I test a regular expression online?
Enter your regex pattern in the pattern field, add any flags (g for global, i for case-insensitive, m for multiline), and paste your test string below. Matches are highlighted instantly as you type, and a results table shows each match with its position and capture groups.
What regex flavor does this tester use?
This tester uses JavaScript's built-in regular expression engine, which supports features like capture groups, lookaheads, lookbehinds, named groups, and Unicode property escapes. It matches the behavior you get in Node.js and browser-based JavaScript code.
What is the difference between the g, i, and m regex flags?
The g (global) flag finds all matches instead of stopping at the first. The i (case-insensitive) flag ignores letter casing. The m (multiline) flag makes ^ and $ match the start and end of each line instead of the entire string.
How do capture groups work in regex?
Capture groups are defined by parentheses in your pattern. They extract specific parts of a match for use in replacements or code. For example, the pattern (\d{4})-(\d{2})-(\d{2}) captures year, month, and day separately from a date string.