A quick reference for regular expression syntax. All examples use JavaScript-compatible regex.
Anchors
| Pattern | Description | Example |
|---|---|---|
| ^ | Start of string (or line in multiline mode) | ^Hello → matches "Hello world" |
| $ | End of string (or line in multiline mode) | world$ → matches "Hello world" |
| \b | Word boundary | \bcat\b → "cat" but not "catch" |
| \B | Non-word boundary | \Bcat → matches "scat" |
Character Classes
| Pattern | Matches |
|---|---|
| . | Any character except newline |
| \d | Digit [0-9] |
| \D | Non-digit |
| \w | Word character [a-zA-Z0-9_] |
| \W | Non-word character |
| \s | Whitespace (space, tab, newline) |
| \S | Non-whitespace |
| [abc] | Any of: a, b, c |
| [^abc] | Any character except a, b, c |
| [a-z] | Any lowercase letter |
| [a-zA-Z0-9] | Any letter or digit |
Quantifiers
| Pattern | Matches | Greedy? |
|---|---|---|
| * | Zero or more | Yes |
| + | One or more | Yes |
| ? | Zero or one | Yes |
| {n} | Exactly n times | — |
| {n,} | n or more times | Yes |
| {n,m} | Between n and m times | Yes |
| *? | Zero or more (lazy) | No |
| +? | One or more (lazy) | No |
Groups & Alternation
| Pattern | Description |
|---|---|
| (abc) | Capturing group |
| (?:abc) | Non-capturing group |
| (?<name>abc) | Named capturing group |
| a|b | a or b |
| \1 | Backreference to group 1 |
| \k<name> | Backreference to named group |
Lookahead & Lookbehind
| Pattern | Name | Description |
|---|---|---|
| (?=abc) | Positive lookahead | Followed by abc |
| (?!abc) | Negative lookahead | Not followed by abc |
| (?<=abc) | Positive lookbehind | Preceded by abc |
| (?<!abc) | Negative lookbehind | Not preceded by abc |
Flags (JavaScript)
| Flag | Name | Effect |
|---|---|---|
| g | Global | Find all matches, not just the first |
| i | Case-insensitive | Ignore case |
| m | Multiline | ^ and $ match start/end of each line |
| s | Dotall | . matches newline characters too |
| u | Unicode | Enable full Unicode matching |
| d | Indices | Populate match.indices with group positions |
Common Patterns
Email
^[^\s@]+@[^\s@]+\.[^\s@]+$URL
https?://[^\s/$.?#].[^\s]*IPv4
\b(?:\d{1,3}\.){3}\d{1,3}\bHex color
#(?:[0-9a-fA-F]{3}){1,2}\bDate (YYYY-MM-DD)
\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])Slug
^[a-z0-9]+(?:-[a-z0-9]+)*$UUID v4
[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}JWT
^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$Test your regex patterns in real time with the Regex Tester tool.