Loading...
Description
| Syntax | Description | Example | Matches |
|---|---|---|---|
| . | Any character except newline | a.c | abc |
| \d | Digit [0-9] | \d+ | 123 |
| \D | Non-digit | \D+ | abc |
| \w | Word char [a-zA-Z0-9_] | \w+ | hello_123 |
| \W | Non-word character | \W+ | !@# |
| \s | Whitespace | \s+ | |
| \S | Non-whitespace | \S+ | hello |
| [abc] | Character set (a, b, or c) | [aeiou] | apple |
| [^abc] | Negated set (not a, b, c) | [^aeiou] | rhythm |
| [a-z] | Range (a through z) | [a-z]+ | hello |
| Syntax | Description | Example | Matches |
|---|---|---|---|
| ^ | Start of string/line | ^Hello | Hello World |
| $ | End of string/line | Hello World | World$ |
| \b | Word boundary | \bcat\b | the cat sat |
| \B | Non-word boundary | \Bcat\B | concatenate |
| Syntax | Description | Example | Matches |
|---|---|---|---|
| * | Zero or more (greedy) | ab*c | ac, abc, abbc |
| + | One or more (greedy) | ab+c | abc, abbc (not ac) |
| ? | Zero or one (optional) | colou?r | color, colour |
| {n} | Exactly n times | \d{3} | 123 |
| {n,} | n or more times | \d{2,} | 12, 123, 1234 |
| {n,m} | Between n and m times | \d{2,4} | 12, 123, 1234 |
| *? | Zero or more (lazy) | ab*?c | ac |
| +? | One or more (lazy) | ab+?c | abc |
| Syntax | Description | Example | Matches |
|---|---|---|---|
| (abc) | Capture group | (\w+)@(\w+) | user@host |
| (?:abc) | Non-capturing group | (?:Mr|Ms)\. \w+ | Mr. Smith |
| (?<name>abc) | Named capture group | (?<year>\d{4}) | 2024 |
| a(?=b) | Positive lookahead (a followed by b) | foo(?=bar) | foobar |
| a(?!b) | Negative lookahead (a not followed by b) | foo(?!bar) | foobaz |
| (?<=a)b | Positive lookbehind (b preceded by a) | (?<=@)\w+ | @user |
| (?<!a)b | Negative lookbehind (b not preceded by a) | (?<!@)\w+ | user |
| a|b | Alternation (a or b) | cat|dog | I have a dog |
| Syntax | Description | Example | Matches |
|---|---|---|---|
| g | Global (match all occurrences) | /test/g | test test test |
| i | Case-insensitive | /test/i | TEST |
| m | Multiline (^ and $ match line boundaries) | m: /^test/m | line1\ntest |
| s | Dotall (. matches newline) | s: /test.s/s | test\ns |
| u | Unicode mode | u: /\\u{1F600}/u | 😀 |
| Syntax | Description | Example | Matches |
|---|---|---|---|
| ^[\w.-]+@[\w.-]+\.\w+$ | Email address | ^([\w.-]+@[\w.-]+\.\w+)$ | user@example.com |
| https?://[\w.-]+(:\d+)?/[\w./?#&=-]* | URL | (https?://[\w.-]+(?:/\S*)?) | https://example.com/path?q=1 |
| \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} | IPv4 address | (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) | 192.168.1.1 |
| \d{4}-\d{2}-\d{2} | Date (YYYY-MM-DD) | (\d{4}-\d{2}-\d{2}) | 2024-06-20 |
| \d{3}-\d{3}-\d{4} | Phone (US) | (\d{3}-\d{3}-\d{4}) | 555-123-4567 |
| #[0-9a-fA-F]{6} | Hex color | (#[0-9a-fA-F]{6}) | #FF5733 |