A Regex Cheat Sheet for Developers
Regular expressions (regex) are a superpower for text pattern-matching, but the syntax is genuinely hard to remember. This cheat sheet covers the patterns you'll actually reach for day to day.
Common building blocks
- \d — any digit (0-9)
- \w — a word character (letters, digits, underscore)
- \s — whitespace (space, tab, newline)
- + — one or more times
- * — zero or more times
- ? — optional (zero or one time)
- ^ and $ — start and end of the string
- [...] — a character set, e.g. [a-z] matches any lowercase letter
Ready-to-use patterns
Email: ^[\w.+-]+@[\w-]+\.[a-zA-Z]{2,}$
URL: ^https?:\/\/[\w.-]+\.[a-zA-Z]{2,}(\/\S*)?$
Phone (IN): ^[6-9]\d{9}$
Hex color: ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
Strong pwd: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}$Writing a regex is one thing, testing it is another — a single typo can break the whole pattern. In our Regex Tester you can enter both a pattern and a test string live and see matches highlighted instantly, without running console.log() in a browser console.
Try it yourself
Regex Tester