
Regex Cheat Sheet: 10 Patterns That Handle 90% of Real Work
I've been writing regex for years and I still look things up constantly. The problem with most cheat sheets is they list every possible syntax token without telling you which ones you'll actually use. Below are my working references, the patterns I reach for over and over. The six characters you need to know \d → any digit (0-9) \w → any word character (letter, digit, underscore) \s → any whitespace (space, tab, newline) \D → any NON-digit \W → any NON-word character \S → any NON-whitespace Uppercase = inverse. That's the whole pattern. Quantifiers + one or more * zero or more ? zero or one (optional) {3} exactly 3 {2,5} between 2 and 5 {3,} 3 or more The * vs + distinction matters: \d* matches an empty string (zero digits is fine). \d+ requires at least one digit. When in doubt, you want + . The 10 patterns I copy-paste the most 1. Email [\w.-]+@[\w.-]+\.\w{2,} Not RFC-perfect. Doesn't need to be. Handles real-world emails. const emails = text . match ( / [\w .- ] +@ [\w .- ] + \.\w{2
Continue reading on Dev.to JavaScript
Opens in a new tab



