๐งช Regex & Test Input
๐ Results
Enter a pattern and test string to see results
๐ About Regular Expressions
Master regular expressions with this comprehensive guide and testing tool
What is a Regular Expression?
A regular expression (or regex/regexp) is a sequence of characters that define a search pattern. Used for:
- Pattern matching: Find specific text patterns
- Validation: Validate email, phone, dates, etc.
- Text extraction: Extract data from text
- Search and replace: Find and replace patterns
- Data cleaning: Clean and format data
- Parsing: Parse structured text data
Basic Syntax
Literal: abc - matches "abc"
Dot: a.c - matches "abc", "adc", etc.
Character class: [abc] - matches a, b, or c
Negation: [^abc] - matches any char except a, b, c
Range: [a-z] - matches lowercase letters
Quantifiers
* - 0 or more times
+ - 1 or more times
? - 0 or 1 time (optional)
{n} - exactly n times
{n,m} - between n and m times
{n,} - n or more times
Anchors & Escapes
^ - start of string
$ - end of string
\b - word boundary
\d - digit [0-9]
\w - word char [a-zA-Z0-9_]
\s - whitespace
Common Regex Patterns
๐ง Email Address
๐ฑ Phone (US Format)
๐ URL
๐ Date (YYYY-MM-DD)
๐ณ Credit Card
๐ Strong Password
Groups & Capture
(abc) - capture group
(?:abc) - non-capturing group
(?=abc) - positive lookahead
(?!abc) - negative lookahead
\1, \2 - back references
Alternation & Operators
| - OR operator (cat|dog)
\ - escape special chars
. - any character except newline
- - range in character class
How to Use This Regex Tester
๐ Step-by-Step Guide:
- Enter your regular expression pattern in the Pattern field
- Enter the text to test against in the Text area
- Select regex flags if needed (g, i, m, s)
- Click Test to see matches
- View matches highlighted in the output with details
- Adjust pattern and re-test as needed
Regex Flags & Modifiers
g - Global (find all matches)
i - Case insensitive matching
m - Multiline (^ and $ per line)
s - Dot matches newlines
u - Unicode matching
y - Sticky matching
Tips & Best Practices
- Start simple, then add complexity
- Test with edge cases
- Use non-greedy matching (.*?) when needed
- Escape special characters properly
- Comment complex patterns
- Use tools to visualize patterns
Common Regex Mistakes
โ Greedy Quantifiers
Problem: .* matches too much. Solution: Use .*? for non-greedy matching.
โ Unescaped Special Chars
Problem: . matches any char. Solution: Use \. to match literal dot.
โ Wrong Flags
Problem: Case sensitive when not needed. Solution: Use 'i' flag for case-insensitive.
โ Missing Global Flag
Problem: Only finds first match. Solution: Add 'g' flag to find all.
Advanced Features
- Lookahead: (?=pattern)
- Lookbehind: (?<=pattern)
- Named groups: (?P<name>...)
- Unicode escapes: \uXXXX
- Backreferences: \1, \2
Related Tools
- URL Encoder - Encode/decode URLs
- Base64 Encoder - Base64 encoding
- JSON Formatter - Format JSON