6.11. Regex Syntax Look Ahead/Behind
6.11.1. Syntax
(?=)
- Lookahead(?<=)
- Lookbehind(?!foo)
- Negative Lookahead(?<!foo)
- Negative Lookbehind\K
- Stop Look Behind
6.11.2. Example
(?=foo)
- asserts that what immediately follows the current position in the string isfoo
(?<=foo)
- asserts that what immediately precedes the current position in the string isfoo
(?!foo)
- Asserts that what immediately follows the current position in the string is not foo(?<!foo)
- Asserts that what immediately precedes the current position in the string is not foo^\s+sh '\K.+(?=')
- if line starts withsh
at any indentation, then take the content of whats inside of apostrophesd(?=r)
- matches ad
only if is followed byr
, butr
will not be part of the overall regex match(?<=r)d
- matches ad
only if is preceded by anr
, butr
will not be part of the overall regex match