Regular expressions 101: a practical guide for developers
What is a regular expression?
A regular expression is a sequence of characters that defines a search pattern. It is used for string matching, extraction, find-and-replace, and validation across virtually every programming language.
Core building blocks
| Pattern | Matches | Example |
|---|---|---|
. | Any character except newline | c.t matches cat, cut, cot |
* | Zero or more of preceding | ab*c matches ac, abc, abbc |
+ | One or more of preceding | ab+c matches abc, abbc but not ac |
? | Zero or one of preceding | colou?r matches color, colour |
\d | Any digit (0-9) | \d{3} matches 123, 456 |
\w | Any word character | \w+ matches hello, test_1 |
Common use cases
Email validation is one of the most common regex applications. While a perfect email regex is notoriously complex, a practical pattern catches most real-world inputs:
/^[^\s@]+@[^\s@]+\.[^\s@]+$/Other frequent use cases include extracting URLs from text, validating phone numbers, parsing log files, and transforming data between formats.
Practical tips
Start simple and add complexity as needed
Use online testers with real-time feedback to iterate quickly
Be careful with greedy quantifiers — they match as much as possible
Use non-capturing groups
(?:...)when you do not need the captured valueTest edge cases: empty strings, very long inputs, special characters
Try the regex tester
The regex tester provides real-time matching, capture group visualization, and a library of common patterns to get you started.