Developer Tools6 min read3 March 2026
Regular Expressions (Regex) Cheat Sheet & Online Tester
A practical regex cheat sheet covering common patterns, flags, character classes, quantifiers, and groups — with an interactive online tester.
What are Regular Expressions?
Regular expressions (regex or regexp) are patterns used to match character combinations in strings. They are supported by virtually every programming language and are indispensable for tasks like form validation, data extraction, search-and-replace, and log parsing.
Basic Syntax
.— matches any single character (except newline)^— start of string$— end of string\d— any digit (0–9)\w— any word character (a–z, A–Z, 0–9, _)\s— any whitespace character\D,\W,\S— negated versions of the above
Quantifiers
*— 0 or more times+— 1 or more times?— 0 or 1 time (optional){n}— exactly n times{n,}— n or more times{n,m}— between n and m times
Character Classes
[abc]— matches a, b, or c[^abc]— matches anything except a, b, or c[a-z]— matches any lowercase letter[0-9]— matches any digit (same as\d)
Groups & Alternation
(abc)— capturing group; captures the match forabc(?:abc)— non-capturing group; groups without capturinga|b— alternation; matches a or b(?=abc)— positive lookahead(?!abc)— negative lookahead
Common Flags
g— global; find all matches, not just the firsti— case-insensitive matchingm— multiline;^and$match start/end of each lines— dotAll;.matches newlines too
Frequently Used Patterns
- Email address:
^[\w.-]+@[\w.-]+\.[a-z]{2,}$ - URL:
https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=%]* - IP address (v4):
^(\d{1,3}\.){3}\d{1,3}$ - Date (YYYY-MM-DD):
^\d{4}-\d{2}-\d{2}$ - Hex colour:
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ - Phone number (India):
^[6-9]\d{9}$
Using the ToolsPal Regex Tester
- Enter your pattern in the regex field
- Set flags (g, i, m) using the toggle buttons
- Paste your test string in the input area
- All matches are highlighted in real time with capture group details shown below
Free Online Tool
Try Regex Tester
Test and debug regular expressions with live match highlighting.