This regex cheat sheet covers the most common regular-expression tokens — character classes, anchors, quantifiers, groups and lookarounds — used in JavaScript, Python, PHP, Java and most other languages. Keep it handy when writing patterns for search, validation and replacement.
| Token | Meaning |
|---|---|
| . | Any character except newline |
| \d | Any digit (0–9) |
| \D | Any non-digit |
| \w | Word character (a–z, A–Z, 0–9, _) |
| \W | Non-word character |
| \s | Whitespace (space, tab, newline) |
| \S | Non-whitespace |
| ^ | Start of string / line |
| $ | End of string / line |
| * | 0 or more of the previous |
| + | 1 or more of the previous |
| ? | 0 or 1 (optional) |
| {n} | Exactly n times |
| {n,} | n or more times |
| {n,m} | Between n and m times |
| [abc] | Any one of a, b, c |
| [^abc] | Any character except a, b, c |
| [a-z] | Any character in the range a–z |
| (…) | Capturing group |
| (?:…) | Non-capturing group |
| (?=…) | Positive lookahead |
| (?!…) | Negative lookahead |
| a|b | a or b (alternation) |
| \b | Word boundary |
| \B | Non-word boundary |
| \\ | Literal backslash |
| \. | Literal dot |
Example
^\d{3}-\d{4}$ matches a phone number like 555-1234: three digits, a hyphen, then four digits, anchored to the whole string.