๐งช Pattern Testing
/
/
๐ Results
0
Matches
0
Groups
0
Characters
No saved patterns yet
^\d{3}-\d{2}-\d{4}$
Social Security Number (US format)
IP Address
IPv4 address validation
^(\+\d{1,3}[- ]?)?\d{10}$
Phone number with optional country code
URL
HTTP/HTTPS URL validation
Strong Password
Min 8 chars, uppercase, lowercase, number, special char
\b\w+(?:\s+\w+)*\b
Extract complete words or phrases
๐ Regex Reference Guide
๐ค Character Classes
Pattern | Description | Example |
---|---|---|
. |
Any character except newline | a.c matches "abc", "axc" |
\d |
Any digit (0-9) | \d{3} matches "123" |
\w |
Word character (a-z, A-Z, 0-9, _) | \w+ matches "hello_123" |
\s |
Whitespace character | \s+ matches spaces/tabs |
[abc] |
Any character in brackets | [aeiou] matches vowels |
[^abc] |
Any character NOT in brackets | [^0-9] matches non-digits |
[a-z] |
Character range | [A-Z] matches uppercase |
๐ข Quantifiers
Pattern | Description | Example |
---|---|---|
* |
0 or more | ab* matches "a", "ab", "abb" |
+ |
1 or more | ab+ matches "ab", "abb" |
? |
0 or 1 (optional) | colou?r matches "color", "colour" |
{n} |
Exactly n times | \d{3} matches exactly 3 digits |
{n,} |
n or more times | \d{3,} matches 3+ digits |
{n,m} |
Between n and m times | \d{3,5} matches 3-5 digits |
โ Anchors
Pattern | Description | Example |
---|---|---|
^ |
Start of string/line | ^Hello matches "Hello world" |
$ |
End of string/line | world$ matches "Hello world" |
\b |
Word boundary | \bcat\b matches "cat" not "catch" |
\B |
Non-word boundary | \Bcat\B matches "cat" in "locate" |
๐ฏ Groups & Captures
Pattern | Description | Example |
---|---|---|
(abc) |
Capturing group | (\d{4})-(\d{2}) captures year/month |
(?:abc) |
Non-capturing group | (?:https?://)(.+) groups protocol |
(a|b) |
Alternation (OR) | (cat|dog) matches "cat" or "dog" |
\1 |
Backreference to group 1 | (\w+)\s+\1 matches repeated words |
๐ Flags
Flag | Description | Example |
---|---|---|
g |
Global (find all matches) | Without: finds first match only |
i |
Case insensitive | hello matches "Hello", "HELLO" |
m |
Multiline (^ and $ match line breaks) | ^start matches line beginnings |
s |
Dot matches newlines | .* includes line breaks |
๐ Lookahead & Lookbehind
Pattern | Description | Example |
---|---|---|
(?=abc) |
Positive lookahead | \d+(?=px) matches numbers before "px" |
(?!abc) |
Negative lookahead | \d+(?!px) matches numbers not before "px" |
(?<=abc) |
Positive lookbehind | (?<=\$)\d+ matches numbers after "$" |
(? |
Negative lookbehind | (? matches numbers not after "$" |
๐ก Tips & Best Practices
- Use
\d
instead of[0-9]
for better readability - Escape special characters:
\.
\+
\*
\?
- Use non-capturing groups
(?:)
when you don't need the capture - Be specific:
[a-zA-Z]
instead of.*
when possible - Test edge cases and validate with real data
- Use word boundaries
\b
to avoid partial matches - Consider performance: avoid nested quantifiers like
(a+)+