7 min read
Regex Basics for Developers
A practical introduction to patterns, groups, anchors and flags.
Patterns and anchors
A regular expression describes a pattern of text. Anchors ^ and $ match the start and end of a line or string, while \d, \w and \s match digit, word and whitespace characters.
Groups and quantifiers
Parentheses create capture groups you can read back from a match. Quantifiers like *, +, ? and {n,m} control how many times the previous token repeats.
- •* means zero or more
- •+ means one or more
- •? means zero or one
Flags
g finds all matches, i ignores case, m makes anchors work per line, and s lets the dot match newlines. Test flags live against realistic sample text.
Try it yourself
Test regular expressions live against sample text with flags, matches and capture groups. Runs locally in your browser.
Open Regex Tester