Regular expressions (regex) are patterns used to match, search, and manipulate text. They appear in programming, command-line tools, text editors, and database queries. Here is a practical cheat sheet and how to test patterns instantly.
Regex Basics
.— Matches any single character except newline.*— Matches 0 or more of the preceding element.+— Matches 1 or more of the preceding element.?— Matches 0 or 1 of the preceding element (makes it optional).^— Matches start of string.$— Matches end of string.[]— Character class.[abc]matches a, b or c.[^]— Negated class.[^abc]matches anything except a, b, c.{n,m}— Matches between n and m repetitions.|— Alternation (OR).cat|dogmatches cat or dog.()— Capturing group.\d— Digit (0-9).\Dis non-digit.\w— Word character (a-z, A-Z, 0-9, _).\Wis non-word.\s— Whitespace.\Sis non-whitespace.\b— Word boundary.
Common Regex Patterns
- Email:
[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} - URL:
https?:\/\/[^\s/$.?#].[^\s]* - IP Address:
\b(?:\d{1,3}\.){3}\d{1,3}\b - Date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2} - Phone (US):
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4} - Hex color:
#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})
How to Test Regex Online
Use Anonymiz Regex Tester — paste your pattern and test string, and see matches highlighted in real time. Supports JavaScript regex syntax. Free, runs in your browser.
Regex Flags
g— Global: find all matches, not just the first.i— Case-insensitive.m— Multiline:^and$match start/end of each line.s— Dotall:.matches newlines too.


