Basics
Look around basics
Lookarounds often cause confusion to new regex learners. There are four lookarounds:
(?<= … ) and (?= … ),
(?<! … ) and (?! … )
Collectively, lookbehinds and lookaheads are known as lookarounds. Let’s see the following table of examples:
Lookaround | Name | What it Does |
---|---|---|
(?=learn) |
Lookahead | Asserts that what immediately follows the current position in the string is learn |
(?<=learn) |
Lookbehind | Asserts that what immediately precedes the current position in the string is learn |
(?!learn) |
Negative Lookahead | Asserts that what immediately follows the current position in the string is not learn |
(?<!learn) |
Negative Lookbehind | Asserts that what immediately precedes the current position in the string is not learn |
Get hands-on with 1400+ tech skills courses.