Regular Expression Tester
🔍 What is Regular Expression?
Regular expressions (regex or regexp) are powerful pattern-matching tools used for searching, validating, and manipulating text. They provide a concise and flexible way to identify strings of text matching specific patterns, making them essential for data validation, parsing, text processing, and search operations.
This professional regex tester provides real-time pattern matching with syntax highlighting, capture group visualization, and replacement functionality. Essential for developers, data analysts, system administrators, and anyone working with text processing and pattern matching.
⚙️ How This Regex Tester Works
This tool uses Rust's robust regex engine to provide accurate, fast pattern matching with detailed feedback. Simply enter your pattern, test text, and see instant results with visual highlighting.
🔥 Key Features:
- Real-time Matching: Instant pattern evaluation as you type
- Visual Highlighting: Matched text highlighted in yellow for easy identification
- Match Counter: Display total number of matches found
- Capture Groups: Detailed table showing all capture groups for each match
- Regex Flags: Support for case-insensitive (i) and multiline (m) modes
- Replace Functionality: Test replacements with group references ($1, $2, etc.)
- Error Validation: Clear error messages for invalid patterns
- Quick Examples: 8+ common regex patterns for quick reference
- Persistent Settings: Auto-save flags to Local Storage
- One-Click Copy: Click replaced text to copy results
🎯 How to Use:
- Enter Pattern: Type your regex pattern in the first field (e.g.,
\d+) - Add Test Text: Enter the text you want to test against
- Set Flags: Enable case-insensitive or multiline mode if needed
- View Results: See highlighted matches, match count, and capture groups
- Test Replacement: Enter replacement string to see how replace would work
✨ Advanced Features Supported:
✅ Backreferences (\1, \2, etc.) are FULLY supported!
This tool uses fancy-regex engine, providing full PCRE-compatible features including backreferences and advanced lookahead/lookbehind assertions.
Examples that work:
\b(\w+)\s+\1\b- finds duplicate words like "the the"(['\"]).*?\1- matches text in paired quotes<(\w+)>.*?</\1>- matches paired HTML tags
Full support for: Capture groups, backreferences, lookahead/lookbehind, atomic groups, and more advanced PCRE features!
📚 Regex Syntax Quick Reference
Basic Patterns
| Pattern | Description | Example |
|---|---|---|
. | Any character except newline | a.c matches "abc", "a1c" |
\d | Any digit [0-9] | \d+ matches "123", "4567" |
\w | Word character [a-zA-Z0-9_] | \w+ matches "hello", "user_123" |
\s | Whitespace (space, tab, newline) | \s+ matches " ", " " |
\D \W \S | Negated (NOT digit, word, space) | \D matches non-digits |
Quantifiers
* | 0 or more | a* matches "", "a", "aaa" |
+ | 1 or more | a+ matches "a", "aaa" |
? | 0 or 1 (optional) | colou?r matches "color", "colour" |
{n} | Exactly n times | \d{3} matches "123", "456" |
{n,m} | Between n and m times | \d{2,4} matches "12", "123", "1234" |
Anchors & Boundaries
^ | Start of string/line | ^Hello matches "Hello world" |
$ | End of string/line | world$ matches "Hello world" |
\b | Word boundary | \bcat\b matches "cat" but not "catch" |
\B | Non-word boundary | \Bcat matches "catch" but not "cat" |
Character Classes
[abc] | Any of a, b, or c | [aeiou] matches any vowel |
[^abc] | NOT a, b, or c | [^0-9] matches non-digits |
[a-z] | Range from a to z | [A-Z] matches uppercase letters |
[a-zA-Z0-9] | Alphanumeric characters | Matches letters and numbers |
Groups & Capturing
(abc) | Capture group | (\d{3})-(\d{4}) captures area code and number |
(?:abc) | Non-capturing group | Groups without capturing |
a|b | Alternation (OR) | cat|dog matches "cat" or "dog" |
💼 Real-World Use Cases
1. 📧 Email Validation
Pattern:
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\bMatches:
- user@example.com
- john.doe@company.co.uk
- admin+test@domain.io
2. 📱 Phone Number Extraction
US Format Pattern:
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}Matches:
- (555) 123-4567
- 555-123-4567
- 555.123.4567
- 5551234567
3. 🌐 URL Parsing & Validation
HTTP/HTTPS Pattern:
https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&/=]*)With Capture Groups (protocol, domain, path):
(https?)://([^/]+)(/.*)?
4. 💳 Credit Card Number Validation
Pattern (with optional spaces/dashes):
\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}Note: This validates format only. Use Luhn algorithm for actual validation.
5. 🔐 Password Strength Validation
At least 8 chars, 1 uppercase, 1 lowercase, 1 digit:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$6. 🌍 IP Address Extraction
IPv4 Pattern:
\b(?:(?: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]?)\bMatches: 192.168.1.1, 10.0.0.255, 255.255.255.0
7. 📅 Date Format Extraction
YYYY-MM-DD Format:
(\d{4})-(\d{2})-(\d{2})DD/MM/YYYY or MM/DD/YYYY:
(\d{1,2})[/-](\d{1,2})[/-](\d{4})8. 🎨 Hex Color Code Extraction
Pattern:
#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\bMatches: #ffffff, #fff, #1a2b3c
9. 🔄 Backreferences - Duplicate Word Detection
Find Duplicate Words:
\b(\w+)\s+\1\b
Matches: "the the", "hello hello", "test test"
Paired Quotes:
(['\"])(?:(?!\1).)*\1
Matches: "hello", 'world', but not "mixed'
Paired HTML Tags:
<(\w+)[^>]*>.*?</\1>
Matches: <div>content</div>, <span>text</span>
Note: \1 references the first capture group, \2 the second, etc. The backreference must match the EXACT same text that was captured.
📚 Step-by-Step Tutorials
Tutorial 1: Extracting Email Addresses from Text
Step 1: Prepare Your Pattern
Enter this email pattern:
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\bStep 2: Add Test Text
Contact us at support@example.com or sales@company.co.uk For urgent matters: admin+urgent@domain.io
Step 3: View Results
You'll see 3 matches highlighted, with all email addresses clearly identified.
Tutorial 2: Reformatting Phone Numbers
Step 1: Capture Groups Pattern
(\d{3})[-.]?(\d{3})[-.]?(\d{4})Step 2: Test Text
555-123-4567 555.987.6543 5551112222
Step 3: Format with Replacement
Replacement string: ($1) $2-$3
Result:
(555) 123-4567 (555) 987-6543 (555) 111-2222
Tutorial 3: Validating and Parsing URLs
Step 1: URL Pattern with Capture Groups
(https?)://([^/\s]+)(/.*)?
Step 2: Test URLs
https://www.example.com/path/to/page http://api.domain.io/v1/users https://subdomain.site.org/blog/post-123
Step 3: View Capture Groups
The capture groups table will show:
- Group 1: Protocol (https, http)
- Group 2: Domain (www.example.com, api.domain.io)
- Group 3: Path (/path/to/page, /v1/users)
❓ Frequently Asked Questions
Q: What regex syntax does this tool support?
A: This tool uses Rust's regex engine, which supports most standard regex features including:
- Standard character classes (\d, \w, \s, etc.)
- Quantifiers (*, +, ?, {n,m})
- Anchors (^, $, \b, \B)
- Capture groups and backreferences
- Character ranges and negation
- Alternation (|)
- Lookahead and lookbehind assertions
Q: How do I use capture groups in replacements?
A: Use $1, $2, $3, etc. to reference capture groups in order:
- $0 - entire match
- $1 - first capture group
- $2 - second capture group
- And so on...
Example: Pattern (\d{3})-(\d{4}) with replacement $1.$2 converts "555-1234" to "555.1234"
Q: What's the difference between case-insensitive and multiline flags?
A:
- Case Insensitive (i): Makes pattern matching ignore letter case. "hello" matches "Hello", "HELLO", "hElLo"
- Multiline (m): Makes ^ and $ match start/end of each line, not just start/end of entire string
Q: Why isn't my pattern matching?
A: Common issues:
- Escape special characters: Use \\ before special chars like . * + ? [ ] ( ) { } ^ $ |
- Check anchors: ^ and $ are strict. Remove if you want partial matches
- Word boundaries: \\b requires word/non-word transition
- Case sensitivity: Enable case-insensitive flag if needed
- Greedy vs non-greedy: Use *? or +? for non-greedy matching
Q: Is my data safe?
A: Yes! All regex processing happens entirely in your browser using WebAssembly. No data is sent to any server. Your patterns and test text never leave your computer.
Q: Can I test regex for other programming languages?
A: Rust regex is very similar to PCRE (Perl-Compatible Regular Expressions) used by many languages. However, there are some differences:
- Compatible: Python (re module), JavaScript (mostly), Go, Ruby
- Slight differences: Some advanced features may vary
- Not supported: Some Perl-specific features like (?{code})
Q: Do backreferences (\1, \2) work?
A: Yes! This tool uses fancy-regex engine which FULLY supports backreferences and advanced PCRE features.
Examples that work perfectly:
\b(\w+)\s+\1\b- matches duplicate words like "the the"(['\"]).*?\1- matches text in paired quotes ("hello" or 'world')<(\w+)>.*?</\1>- matches paired HTML tags like <div>...</div>(\w+)\s+\1\s+\1- matches words repeated 3 times
How to use backreferences:
- Create a capture group with parentheses:
(pattern) - Reference it later with:
\1for first group,\2for second, etc. - The backreference matches the EXACT same text that was captured
Replacements also work: Use $1, $2, etc. in replacement strings to reference captured groups.
Note: Backreferences can be slower than simple patterns, but this tool handles them efficiently for most practical use cases.
Q: What are lookahead and lookbehind?
A: Assertions that match position, not characters:
- Positive Lookahead (?=...): Match if followed by pattern.
\\d+(?=px)matches "10" in "10px" - Negative Lookahead (?!...): Match if NOT followed by pattern
- Positive Lookbehind (?<=...): Match if preceded by pattern
- Negative Lookbehind (?<!...): Match if NOT preceded by pattern
🎯 Best Practices & Tips
- Start Simple: Build complex patterns incrementally, testing at each step
- Use Raw Strings: In most languages, use raw strings (r"..." in Python, r#"..."# in Rust) to avoid double-escaping
- Be Specific: Avoid overly broad patterns like .* when more specific alternatives exist
- Use Non-Capturing Groups: Use (?:...) when you don't need to capture the group
- Anchor When Possible: Use ^ and $ for validation to ensure entire string matches
- Test Edge Cases: Test with empty strings, special characters, unicode, very long inputs
- Performance Matters: Avoid catastrophic backtracking with patterns like (a+)+
- Document Complex Patterns: Add comments explaining what each part does
- Use Character Classes: [0-9] is clearer than \\d in some contexts
- Validate, Don't Parse: For complex formats (HTML, JSON), use proper parsers, not regex
- Learn by Example: Study the Quick Examples for common patterns
- Copy for Reuse: Click replaced text output to copy results
🔗 Related Tools
- Base32 Encoder/Decoder - Encode and decode Base32 data for TOTP, 2FA secrets, and human-readable encoding
- Base64 Encoder/Decoder - Encode and decode Base64 data with support for files and URLs
- ASCII Converter - Convert text to ASCII codes and vice versa with multiple formats
- JSON Formatter & Converter - Format, validate, minify and beautify JSON data with error detection
- HTML Entity Converter - Encode and decode HTML entities for safe web content display
- Text Case Converter - Convert between camelCase, PascalCase, snake_case, kebab-case, and more
Regex Flags
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b