I was trying to learn about positive/negative lookarounds, and I found this stack overflow answer that confused me:
- Positive lookahead:
Syntax:
(?=REGEX_1)REGEX_2
Match only if REGEX_1 matches; after matching REGEX_1, the match is discarded and searching for REGEX_2 starts at the same position.
Maybe this is really straightforward and obvious, but I can't comprehend it. If the syntax were REGEX_2(?=REGEX_1)
, I'd understand, but not the way it's written.
Can someone explain what it means to have a lookahead at the beginning of a regex, how that differs from putting a lookahead at the end, and the value of doing so? I'd also like to ask the same question but about lookbehind at the end. I learn best from concrete examples. Thanks.