Need to test patterns live? Try the Regex Tester.Open Regex Tool →
Regular Expressions Pocket Guide
A quick reference for Regular Expressions. Write powerful patterns to match, search, and replace text.
Character Classes
| Key / Code | Description |
|---|---|
| . | Any character (except newline) |
| \d | Digit (0-9) |
| \w | Word character (a-z, A-Z, 0-9, _) |
| \s | Whitespace (space, tab, newline) |
| [abc] | Any of a, b, or c |
| [^abc] | Not a, b, or c |
| [a-z] | Character range a to z |
Quantifiers
| Key / Code | Description |
|---|---|
| * | 0 or more |
| + | 1 or more |
| ? | 0 or 1 (optional) |
| {3} | Exactly 3 times |
| {2,5} | Between 2 and 5 times |
Anchors & Groups
| Key / Code | Description |
|---|---|
| ^ | Start of string/line |
| $ | End of string/line |
| \b | Word boundary |
| (...) | Group |
| (?:...) | Non-capturing group |
Common Patterns
| Key / Code | Description |
|---|---|
| ^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ | |
| ISO Date (YYYY-MM-DD) | ^\d{4}-\d{2}-\d{2}$ |
| Hex Color | ^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$ |
When to Use Regex
Regex is useful for validation, extraction, lightweight parsing, log scanning, and search-and-replace tasks where the input structure is still text. It works best when the pattern is narrow and testable, not when you are trying to fully parse complex nested languages like HTML or SQL with one expression.
Common Regex Mistakes
The most common problem is making patterns too greedy and accidentally matching more text than intended. Another is forgetting to escape metacharacters such as dots and brackets. In production code, it is also easy to forget multiline, unicode, or case-insensitive flags and then misdiagnose the match failure.
Related
Knowledge is power.