Regex
Lookaround
Zero-width assertions around a position.
By EZ4Code Team
lookaheadlookbehindassertion
Code
(?=abc) positive lookahead
(?!abc) negative lookahead
(?<=abc) positive lookbehind
(?<!abc) negative lookbehind
a(?=b) a followed by b
a(?!b) a not followed by b
(?<=a)b b preceded by a
(?<!a)b b not preceded by aExplanation
Lookaround assertions match a position based on what follows (lookahead) or precedes (lookbehind) without consuming characters. Positive forms require the pattern to match; negative forms require it not to match. Modern JavaScript supports variable-length lookbehind, but some engines (Java, older browsers) restrict lookbehind to fixed length.