Regex Pattern Generator
Create, test, and optimize regular expressions with our interactive tool. Generate regex patterns for validation,
text processing, and pattern matching in any programming language.
Regex Cheat Sheet
Quick reference for common regex patterns and syntax:
Character Classes
| Pattern |
Description |
Example |
. |
Any character except newline |
a.c matches "abc", "a c", etc. |
\d |
Digit (0-9) |
\d\d matches "42" |
\D |
Not a digit |
\D\D matches "ab" |
\w |
Word character (a-z, A-Z, 0-9, _) |
\w+ matches "hello_123" |
\W |
Not a word character |
\W matches "@" in "email@domain" |
\s |
Whitespace (space, tab, newline) |
\s+ matches " \t" |
\S |
Not whitespace |
\S+ matches "abc123" |
[abc] |
Any of a, b, or c |
[aeiou] matches vowels |
[^abc] |
Not a, b, or c |
[^0-9] matches non-digits |
Quantifiers
| Pattern |
Description |
Example |
* |
0 or more |
a*b matches "b", "ab", "aab", etc. |
+ |
1 or more |
a+b matches "ab", "aab", but not "b" |
? |
0 or 1 |
colou?r matches "color" and "colour" |
{n} |
Exactly n |
\d{3} matches "123" |
{n,} |
n or more |
\d{2,} matches "12" and "12345" |
{n,m} |
Between n and m |
\d{2,4} matches "12" and "1234" |
Anchors and Boundaries
| Pattern |
Description |
Example |
^ |
Start of string (or line with m flag) |
^Hello matches "Hello" at start |
$ |
End of string (or line with m flag) |
end$ matches "end" at end |
\b |
Word boundary |
\bword\b matches "word" but not "keyword" |
\B |
Not a word boundary |
\Bword\B matches "swordfish" but not "word" |
Common Patterns
| Purpose |
Pattern |
| Email address |
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ |
| URL |
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$ |
| Phone number (US) |
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$ |
| Date (YYYY-MM-DD) |
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$ |
| HTML tag |
<([a-z]+)([^<]+)*(?:>(.*?)<\/\1>|\s+\/>) |