Regex Tester
Test and debug regular expressions online with real-time matching and group highlighting. Free regex tester for JavaScript and Python.
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$Validates email addresses
^https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(\/\S*)?$Matches URLs
^\+?1?[-.]?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}$US phone numbers
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ISO date format
^([01]\d|2[0-3]):[0-5]\d$24-hour time
^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$IPv4 addresses
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$Hex color codes
^\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}$Credit card numbers
^\d{5}(-\d{4})?$US ZIP codes
^\d{3}-\d{2}-\d{4}$Social Security Number
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$Min 8 chars, mixed case, number, symbol
^[a-zA-Z0-9_]{3,16}$3-16 alphanumeric or underscore
^[a-z0-9]+(?:-[a-z0-9]+)*$URL-friendly slug
<([a-z]+)([^<]+)*(?:>(.*)|\/)(\/>|<\/\1>)Matches HTML tags
^\d+$Only digits
^[a-zA-Z]+$Only letters
How to Use Regex Tester
Enter your regex pattern
Type your regular expression pattern in the pattern field. Use standard JavaScript regex syntax (the same as ECMAScript).
Set flags
Choose flags: 'g' (global, find all matches), 'i' (case-insensitive), 'm' (multiline), 's' (dotall), 'u' (Unicode). Combine as needed.
Paste test text
Paste or type the text you want to test against the pattern. Matches highlight in real-time, showing exactly what your regex captures.
Inspect captures
Capture groups (parts in parentheses) are listed separately so you can see what each group extracted. Use this to refine patterns before using them in code.
When to Use Regex Tester
Validating user input
When building forms with regex validation (email, phone, URL, custom IDs), test patterns against various inputs first. Edge cases like international emails ('user@münchen.de'), parenthesized phone numbers, and URLs with special chars catch many naive patterns. Test thoroughly before deploying.
Search and replace operations
Before running 'find and replace with regex' across thousands of files, test the pattern on a representative sample. Verify it matches what you intend, doesn't match what you don't intend, and handles edge cases (empty matches, lazy vs greedy quantifiers). Saves hours of fixing mass-replacement mistakes.
Log file parsing
Server logs, application logs, and system logs often need regex extraction for monitoring, alerting, and analysis. Test regex against actual log samples to ensure it handles all variants — different timestamp formats, optional fields, multi-line entries, escaped special characters.
Data extraction from semi-structured text
Scraping prices from HTML, extracting dates from documents, parsing CSVs with embedded commas — regex shines when data isn't strictly structured. Test patterns interactively here to refine extraction logic before hardcoding into your application.
Regex Tester Examples
Email validation
Pattern: ^[^\s@]+@[^\s@]+\.[^\s@]+$\nFlags: i\nTest: alice@example.comMATCH at position 0-19A simple email pattern: characters before @, then @, then characters before dot, then dot, then characters until end. Real-world emails have many edge cases (international domains, +addressing, quoted local parts) — production regex should be more thorough or use a dedicated library.
Capture groups
Pattern: (\d{4})-(\d{2})-(\d{2})\nTest: Today is 2026-04-26.Match: 2026-04-26\nGroup 1: 2026\nGroup 2: 04\nGroup 3: 26Parentheses create capture groups that extract specific parts of the match. Useful for parsing structured data: date components, log fields, URL parts. Each group is accessible separately in code (match[1], match[2], etc.).
Greedy vs lazy
Pattern: <.+>\nTest: <p>hello</p>Match: <p>hello</p>Greedy quantifier (+) matches as much as possible — capturing the entire string between first < and last >. To match just the first tag <p>, use lazy quantifier: <.+?> matches '<p>'. Critical for HTML/XML parsing where you usually want the smallest match.
Tips & Best Practices for Regex Tester
- 1.Use regex tester for development; in production, validate inputs server-side too. Client-side regex can be bypassed; server validation prevents data integrity issues regardless of how the request is made.
- 2.Watch for catastrophic backtracking with patterns like (a+)+. Some regex inputs cause exponential time complexity, leading to DoS vulnerabilities. Test with adversarial input (long strings of similar chars) and use atomic groups or possessive quantifiers (where supported) to prevent it.
- 3.For matching across newlines, use the 's' flag (dotall) or [\s\S] which matches any character including newlines. Default '.' doesn't match newlines.
- 4.Use named capture groups (?<name>...) when you have multiple groups — much more readable than referring to match[1], match[2]. JavaScript and most languages support named groups.
- 5.Comment your regex with the 'x' flag (where supported) or use a regex tool that lets you split the pattern across lines with comments. Complex regex without comments is unreadable to anyone who didn't write it (including future you).
- 6.For very complex pattern matching, consider parser combinators or proper parsing libraries instead of regex. Regex isn't ideal for nested structures (HTML, JSON), arbitrary text formats, or context-sensitive grammars.
Frequently Asked Questions
Related Tools
Regex Validator
Validate and test regular expressions online with pattern analysis and match highlighting. Free regex validator with flag options.
AI Regex Generator
Generate regular expressions from plain English descriptions using AI. Free online regex generator that creates patterns from text.
MIME Type Lookup
Look up MIME types by file extension or search MIME types to find associated extensions. Free MIME type reference with 200+ common types.
HTTP Status Code Reference
Searchable HTTP status code reference with descriptions, use cases, and examples. Find any HTTP response code from 1xx to 5xx instantly.
.env File Validator
Validate .env file format, detect duplicate keys, missing values, and syntax issues. Free online dotenv file checker and linter.
Docker Compose Validator
Validate Docker Compose YAML files online instantly. Free docker-compose.yml validator with syntax checking, structure validation, and helpful error messages.