hello@example.comsupport@test.org/\b[\w.-]+@[\w.-]+\.\w+\b/giStandard email address
e.g., user@example.com
/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/iRFC 5322 compliant email
e.g., complex.email+tag@sub.domain.com
/https?://[\w.-]+(?:/[\w.-]*)*/?(?:\?[\w=&.-]*)?/giHTTP/HTTPS URLs
e.g., https://example.com/path?query=value
/\+?1?[-.]?\(?\d{3}\)?[-.]?\d{3}[-.]?\d{4}/gUS phone numbers
e.g., (555) 123-4567
/\+?\d{1,3}[-.\s]?\(?\d{1,4}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,9}/gInternational format
e.g., +44 20 7123 4567
| . | Any character except newline |
| \d | Digit (0-9) |
| \D | Not a digit |
| \w | Word character (a-z, A-Z, 0-9, _) |
| \W | Not a word character |
| \s | Whitespace (space, tab, newline) |
| \S | Not whitespace |
| [abc] | Any of a, b, or c |
| [^abc] | Not a, b, or c |
| [a-z] | Character range a to z |
| [a-zA-Z] | Any letter |
| [0-9] | Any digit |
Test regex patterns in seconds
Type your regular expression in the pattern input field. Use standard regex syntax like \d for digits, \w for word characters, or [a-z] for character ranges. The pattern is automatically validated and highlighted for syntax errors.
Select regex flags: global (g) to find all matches, case-insensitive (i) for case-agnostic matching, multiline (m) for line-by-line processing, or dotall (s) to make dot match newlines. Flags fundamentally change pattern behavior.
Paste your test string in the input area. This could be log files, API responses, user input, or code snippets. Watch matches highlight in real-time as you type or modify the pattern - instant visual feedback on what matches.
Examine highlighted matches in context, view detailed match information (position, length), and inspect capturing groups ($1, $2, etc.). Use the replace feature to test substitutions with backreferences before applying to production code.
Master pattern matching for text processing
Regular expressions (regex) are powerful pattern-matching tools used across virtually every programming language and text processing tool. A regex is a sequence of characters that defines a search pattern, enabling complex text operations like validation, extraction, replacement, and parsing with concise syntax.
Regex originated in the 1950s from formal language theory and became widely available in Unix tools like grep, sed, and awk in the 1970s. Today, regex is built into JavaScript, Python, Java, Go, Ruby, PHP, and nearly every modern language, making it an essential skill for developers. Understanding regex transforms hours of string manipulation into single-line operations.
Data Validation: Verify user input matches expected formats (email addresses, phone numbers, URLs, credit cards). Regex provides precise pattern definitions that simple string operations can't match. For example, validating email format requires checking for username@domain.extension structure with specific character constraints.
Text Extraction: Pull specific data from unstructured text like log files, API responses, or scraped web content. Extract all URLs from HTML, find all phone numbers in a document, or parse timestamps from log entries. Regex excels at finding patterns in noisy data.
Find & Replace: Perform sophisticated text transformations using capturing groups and backreferences. Reformat dates from MM/DD/YYYY to YYYY-MM-DD, convert camelCase to snake_case, or sanitize user input by removing dangerous characters. Single regex operations replace complex loops and conditionals.
Code Search: Find patterns in codebases - locate all function definitions, identify TODO comments, or find hardcoded API keys. IDEs and tools like grep use regex for advanced search capabilities beyond simple string matching.
Character Classes: Match specific character types. \d matches any digit (0-9), \w matches word characters (a-z, A-Z, 0-9, _), \s matches whitespace (space, tab, newline). Negated versions (\D, \W, \S) match opposite characters. Use [abc] to match any of a, b, or c, or [^abc] to match anything except those characters.
Quantifiers: Control how many times a pattern should match. * means zero or more, + means one or more, ? means zero or one (optional), {n} means exactly n times, {n,m} means between n and m times. For example, \d{3} matches exactly three digits, while \w+ matches one or more word characters.
Anchors: Define position requirements. ^ matches start of string/line, $ matches end of string/line, \b matches word boundaries (transition between \w and \W). These prevent partial matches - /^\d{3}$/ matches strings that are exactly three digits, while /\d{3}/ matches any string containing three consecutive digits.
Groups: Parentheses create capturing groups that extract matched substrings. /(\d{3})-(\d{2})-(\d{4})/ matches Social Security Numbers and captures area code, group number, and serial number separately as $1, $2, $3. Non-capturing groups (?:...) match without creating references.
This tester uses JavaScript regex engine, which follows ECMAScript specification. Key features:
Lookaheads/Lookbehinds: Match patterns based on what comes before/after without including it in the match. Positive lookahead (?=...) ensures pattern is followed by something, negative lookahead (?!...) ensures it's not followed. Example: \d+(?= dollars) matches numbers followed by " dollars" but doesn't include "dollars" in the match.
Unicode Support: The 'u' flag enables full Unicode matching, treating emoji and non-ASCII characters correctly. Without 'u', some emoji and extended Unicode characters may be treated as two characters. Always use 'u' flag when working with internationalized text.
Named Capture Groups: (?<name>...) creates named captures for more readable code. Instead of referencing $1, $2, use descriptive names: (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) creates $<year>, $<month>, $<day>.
Greedy vs Lazy Matching: By default, quantifiers are greedy - they match as much as possible. In "test", /<.>/ matches the entire string (from first < to last >), not individual tags. Use lazy quantifiers (?, +?, ??) to match as little as possible: /<.*?>/ matches each tag individually.
Catastrophic Backtracking: Poorly constructed patterns can cause exponential time complexity, hanging your application. Patterns like /(a+)+b/ against "aaaaaaaaaaaaaaaaac" cause catastrophic backtracking as the engine tries all possible ways to divide the 'a' characters between groups. Avoid nested quantifiers on overlapping patterns.
Character Escaping: Special characters (. * + ? ^ $ [ ] { } ( ) | ) must be escaped with backslash to match literally. To match a literal period, use ., not .. Common mistake: using . to mean "any character" when you meant literal period.
Multiline Confusion: Without 'm' flag, ^ and $ match only start/end of entire string. With 'm' flag, they match start/end of each line. Choose based on whether you're processing single strings or multi-line text like log files.
Regex operations can be slow on large text or complex patterns. Performance tips:
Anchor Patterns When Possible: Anchored patterns (^pattern$ or \bword\b) execute faster than unanchored ones because the engine knows where to start matching. If validating format, always anchor.
Avoid Unbounded Quantifiers: Patterns like .text. can scan entire documents. Be specific about what you're matching. Instead of .*, use more targeted patterns like \w+ or [^\s]+.
Compile Once, Use Many: In JavaScript, create RegExp objects outside loops and reuse them. Creating new regex instances repeatedly wastes CPU. let pattern = /\d+/g; for (let line of lines) { pattern.test(line); }
Consider Alternatives: For simple operations, string methods (includes(), startsWith(), split()) are faster than regex. Reserve regex for complex patterns that truly require its power.
Building complex regex requires iterative refinement. Start simple and add complexity incrementally:
Use tools like this tester to visualize matches, experiment with flags, and understand why patterns behave unexpectedly. The ability to see matches highlighted in context dramatically speeds debugging.
While regex syntax is largely standardized, different languages have nuances:
JavaScript: Supports lookaheads and (recently) lookbehinds. No \A or \Z anchors (use ^ and $ with appropriate flags). Named groups added in ES2018.
Python: Supports verbose mode for commented patterns: re.compile(r"\d{3} # area code", re.VERBOSE). Has \A and \Z for absolute string start/end (vs ^ and $ which may match line boundaries).
Java: Requires double escaping in string literals: "\d+" for digit matching (first backslash escapes second backslash). Pattern and Matcher classes for regex operations.
Go: Regex package (regexp) uses RE2 syntax, which guarantees linear time complexity by omitting some features (no backreferences, no lookaheads). Prevents catastrophic backtracking but limits some advanced patterns.
Test patterns in your target language's environment when possible, but JavaScript regex is representative of most flavors.
Text Normalization: Use regex to standardize inconsistent data. Convert various phone formats ((555) 123-4567, 555-123-4567, 555.123.4567) to unified format using capturing groups: phone.replace(/(\d{3})[.-()]?(\d{3})[.-]?(\d{4})/, "$1-$2-$3").
Markdown Parsing: Extract links text, code blocks code, or headers from Markdown using patterns like /[([^]]+)](([^)]+))/ for links.
Log Analysis: Parse structured logs with patterns like /^[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})] (\w+): (.+)$/ to extract timestamp, level, and message from [2024-02-01 10:30:00] INFO: Server started.
Data Sanitization: Remove HTML tags with /<[^>]+>/g, strip script tags with /<script\b[^<](?:(?!</script>)<[^<])*</script>/gi, or sanitize SQL inputs by blocking dangerous patterns.
Regex is a powerful tool that rewards study. Master the basics (character classes, quantifiers, anchors) then progressively learn advanced features (lookarounds, backreferences, non-greedy matching) as needs arise.
How developers use regex in production
Validate email addresses against RFC 5322 standard or simplified patterns for user registration forms. Regex ensures emails match expected structure (username@domain.extension) and contain valid characters, preventing malformed input from reaching your backend.
Extract URLs from text (social media posts, documents, logs) or parse URL components (protocol, domain, path, query parameters). Essential for link detection, web scraping, or analyzing traffic logs to identify external resources.
Parse structured information from application logs, server access logs, or error traces. Extract timestamps, log levels, IP addresses, error codes, or custom data fields. Critical for log analysis, debugging, and monitoring systems.
Remove or replace unwanted characters, strip HTML tags, normalize whitespace, or clean user-generated content. Protect against XSS attacks by removing dangerous patterns, standardize inconsistent data formats, or prepare text for processing.
Master the tester and pattern library
This regex tester provides real-time pattern matching with instant visual feedback, comprehensive syntax reference, and a curated library of common patterns. All processing happens client-side using JavaScript's built-in RegExp engine - your patterns and test data never leave your browser.
Enter your regex pattern in the pattern input field, enclosed by forward slashes (/pattern/). The pattern is automatically validated and any syntax errors are highlighted immediately. Select flags (g, i, m, s, u, y) by clicking the flag buttons - multiple flags can be combined.
Paste your test string in the text area. As you type or modify the pattern, matches highlight in real-time with yellow background. Scroll down to see detailed match information including match position (index), captured groups, and full match text. This instant feedback dramatically speeds pattern development.
Global (g): Find all matches in the text instead of stopping at first match. Essential for find-all operations like extracting all emails or URLs from a document. Without 'g', only the first match is returned.
Case Insensitive (i): Make pattern case-agnostic - /hello/i matches "Hello", "HELLO", "hElLo". Critical for user input validation where case shouldn't matter (email addresses, usernames).
Multiline (m): Change ^ and $ behavior to match start/end of each line instead of entire string. Use when processing multi-line text like log files or CSV data where each line is a separate record.
Dotall (s): Make . (dot) match newline characters. Normally dot matches any character except \n. With 's' flag, dot truly means "any character including newlines". Useful for matching across multiple lines.
Click "Common Patterns" to browse pre-built patterns for email validation, URL extraction, phone numbers, dates, credit cards, and more. Categories include Communication (email, phone, URLs), Web (IP addresses, domains, hex colors), Formats (dates, UUIDs, SSNs), Programming (variables, functions, imports), and Validation (username, password strength, slugs).
Click any pattern to load it into the tester with example text. Modify the pattern to fit your specific needs. The library serves as both a quick solution for common tasks and a learning resource for understanding regex techniques.
Enable the Replace feature to test pattern-based text transformations. Enter replacement text using backreferences ($1, $2, etc.) to refer to captured groups. $& refers to the entire match, $` to text before match, $' to text after match.
Example: Pattern /(\d{3})-(\d{3})-(\d{4})/ with replacement ($1) $2-$3 transforms 555-123-4567 to (555) 123-4567. Test substitutions before applying to production code to verify they work correctly.
The right panel contains a comprehensive regex syntax reference. Search for specific syntax elements using the search box. Expandable sections cover Character Classes (\d, \w, \s), Anchors (^, $, \b), Quantifiers (*, +, ?, {n}), Groups (capturing, non-capturing, lookarounds), Flags, and Special Characters.
Each syntax element includes description and usage examples. Refer to this cheatsheet when building complex patterns or learning new regex features. The examples show real-world usage patterns, not just abstract syntax.
When building complex patterns, start simple and add complexity incrementally. Test at each step:
Use the highlighted matches to see exactly what your pattern captures. If it's not highlighting what you expect, the pattern needs refinement. The real-time feedback makes debugging intuitive.
Everything you need to know about regex
Your patterns and test data never leave your browser
All regex testing happens entirely client-side using your browser's built-in JavaScript RegExp engine. Your patterns and test strings are processed locally in your browser's JavaScript environment - there are no server uploads, no backend processing, and no data transmission to external services.
While this tool itself is private and secure, be aware of regex security implications in your applications:
ReDoS (Regular Expression Denial of Service): Poorly constructed patterns can cause catastrophic backtracking, hanging your application or server. Patterns like /(a+)+b/ against input without 'b' cause exponential time complexity. Avoid nested quantifiers on overlapping patterns. Test patterns with large inputs and adversarial strings before production use.
Input Validation: When using regex to validate user input, always consider bypass attempts. Regex validation is not sufficient for security-critical operations - combine with additional checks, length limits, and sanitization. Never rely solely on regex to prevent SQL injection, XSS, or other injection attacks.
Sensitive Data Exposure: Be cautious when using regex to extract or redact sensitive data. Test thoroughly to ensure patterns capture exactly what you intend - overly broad patterns may leak data, overly narrow patterns may miss sensitive content. For PII redaction, prefer allowlists (keep known-safe patterns) over denylists (remove known-sensitive patterns).
This tester is safe for testing patterns against any data since everything is local and private. Use it to validate patterns before deploying to production systems.
Regex testing capabilities and performance
Showing 8 of 94 related tools