Regex Tester
Test and debug regular expressions in real time with match highlighting, capture groups, and flag controls. Free, client-side, no signup.
How to Use
- Enter your regex pattern in the pattern field (without surrounding slashes).
- Toggle flags (g, i, m, s, u) as needed.
- Type or paste your test string in the text area.
- Matches are highlighted in real time with capture groups displayed below.
Regular Expression Quick Reference
.— matches any single character (except newline without s flag)\d— matches any digit (0-9)\w— matches any word character (a-z, A-Z, 0-9, _)\s— matches any whitespace character*— matches 0 or more of the preceding token+— matches 1 or more of the preceding token?— matches 0 or 1 of the preceding token[abc]— matches any character in the set(group)— capturing group^/$— start / end of string (or line with m flag)
Common Regex Patterns
- Email:
'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}' - URL:
'https?://[^\s/$.?#].[^\s]*' - IP Address:
'\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b' - Phone (US):
'\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}' - Date (YYYY-MM-DD):
'\d{4}-\d{2}-\d{2}'
Tips for Writing Better Regex
Start simple and build complexity gradually. Use non-greedy quantifiers (*?, +?) when you want the shortest match. Prefer specific character classes (\d, [a-z]) over the generic dot (.). Use named capture groups ((?<name>...)) for readability in complex patterns. Always test edge cases including empty strings and unexpected input.
Understanding Capture Groups
Parentheses () create capture groups that extract parts of a match. For example, the pattern (\d+)-(\d+) applied to "2024-03" captures "2024" as group 1 and "03" as group 2. Named groups (?<year>\d+)-(?<month>\d+) make code more readable by labeling captures. Non-capturing groups (?:...) group without capturing — useful for applying quantifiers to a group without creating a backreference.
Lookahead and Lookbehind
Positive lookahead (?=...) matches a position followed by the pattern without consuming it. foo(?=bar) matches "foo" only when followed by "bar". Negative lookahead (?!...) matches when NOT followed by the pattern. Lookbehind works the same way but checks before the current position: (?<=\$)\d+ matches digits preceded by a dollar sign.
Lookbehinds are supported in all modern browsers (Chrome 62+, Firefox 78+, Safari 16.4+) and in most server-side languages. However, some regex engines (like JavaScript) require fixed-length lookbehinds while others (like Python and .NET) allow variable-length.
Performance and Catastrophic Backtracking
Poorly written regex can cause exponential execution time — a problem known as catastrophic backtracking. This typically occurs with nested quantifiers like (a+)+, (a|a)*, or overlapping alternatives. When the regex engine fails to match, it tries every possible permutation of how the quantifiers could divide the input, leading to millions of backtracks.
To avoid this: use atomic groups or possessive quantifiers where available, avoid nesting quantifiers, and prefer specific character classes over broad ones. If a pattern takes noticeably long on certain inputs, it likely has a backtracking problem. This tool limits matches to 10,000 to prevent browser freezes.
Regex in Different Languages
While the core regex syntax is similar across languages, there are important differences. JavaScript uses /pattern/flags literal syntax and the RegExp constructor. Python uses the re module with re.compile() and supports verbose mode re.VERBOSE for readable patterns. Go uses the RE2 engine which guarantees linear-time execution but lacks backreferences and lookarounds. Always consult your language's documentation for supported features.
Related Tools
Use regex with our JSON Formatter to validate patterns in JSON data. Escape regex special characters with the String Escape Tool. Test URL patterns with the URL Encoder. Validate HTML structure (though regex isn't ideal for full HTML parsing). Format SQL queries that use regex-like patterns. Compare text differences with the Diff Checker. Encode regex special characters in HTML with the HTML Entity Encoder.
Learn More
- Regex Cheat Sheet — a quick reference for the most common regex patterns and syntax.
Frequently Asked Questions
- What is a regular expression?
- A regular expression (regex) is a pattern that describes a set of strings. It is used for searching, matching, and manipulating text. Regular expressions are supported in virtually every programming language including JavaScript, Python, Java, Go, and Ruby.
- What do the flags mean?
- g (global) finds all matches instead of stopping at the first. i (case insensitive) ignores uppercase/lowercase differences. m (multiline) makes ^ and $ match line boundaries. s (dotall) makes . match newline characters. u (unicode) enables full Unicode matching.
- Why does my regex cause the page to freeze?
- Some regex patterns cause catastrophic backtracking — exponential time complexity when the engine tries many possible paths. Avoid nested quantifiers like (a+)+ or (a|a)*. If a pattern takes too long, simplify it or use more specific character classes.
- Is my data safe?
- Yes. All regex matching happens in your browser using the native JavaScript RegExp engine. No data is sent to any server.
- Does this use the same regex engine as my programming language?
- This tool uses JavaScript's built-in RegExp engine. While most basic patterns work the same across languages, there are differences in advanced features like lookbehinds, named groups, and Unicode handling. Always test in your target language for production use.
Code Examples
Learn how to use this tool programmatically in your favorite language.
Use this tool from AI agents.
The CodeTidy MCP Server lets Claude, Cursor, and other AI agents
use this tool and 46 others directly. One command: npx @codetidy/mcp