| Pattern | Meaning |
|---|
. | Any character except newline |
\d | Digit [0-9] |
\D | Non-digit [^0-9] |
\w | Word character [a-zA-Z0-9_] |
\W | Non-word character |
\s | Whitespace (space, tab, newline) |
\S | Non-whitespace |
[abc] | Any character in set |
[^abc] | Any character NOT in set |
[a-z] | Character range |
| Pattern | Meaning |
|---|
* | Zero or more |
+ | One or more |
? | Zero or one (optional) |
{n} | Exactly n times |
{n,} | n or more times |
{n,m} | Between n and m times |
*? | Zero or more (lazy) |
+? | One or more (lazy) |
| Pattern | Meaning |
|---|
^ | Start of string/line |
$ | End of string/line |
\b | Word boundary |
\B | Non-word boundary |
| Pattern | Meaning |
|---|
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named capturing group |
\1 | Backreference to group 1 |
(?=abc) | Lookahead |
(?!abc) | Negative lookahead |
(?<=abc) | Lookbehind |
(?<!abc) | Negative lookbehind |
| Flag | Meaning |
|---|
g | Global — find all matches |
i | Case-insensitive |
m | Multiline — ^/$ match line boundaries |
s | Dotall — . matches newline |
u | Unicode support |
- Email:
/^[^\s@]+@[^\s@]+\.[^\s@]+$/ - URL:
/^https?:\/\/.+/ - IP Address:
/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
See 20 Useful Regex Patterns for more examples.
Use our free Regex Tester to test and debug regex patterns in real time.