Member-only story
JavaScript RegExp Advanced Tricks: Master Lookaheads, Lookbehinds, Named Groups, and Modern Regex Features
JavaScript Mastery Series Part 45
Zayd Islam
9 min read11 hours ago
Read Part 44
Press enter or click to view image in full size
You’ve probably used regular expressions before.
Maybe you wanted to:
Validate an email address.
Extract numbers from a string.
Find words inside a paragraph.
Replace unwanted characters.
Check whether a password meets certain requirements.
But JavaScript regular expressions have some surprisingly powerful features that many developers rarely use.
Imagine searching for a number that is followed by a specific word, without including that word in the match.
Or extracting a date and giving each part a meaningful name.
Or finding a word only when it is not preceded by another word.
These are exactly the kinds of problems advanced regular expressions can solve.
Let’s explore the techniques that make JavaScript regex much more powerful.
1.…