I'm used to the standard usage of lookahead and lookbehind assertions like so
(for e.g.): .(?=foo)
and (?<=foo).
. That is in lookahead case we need to place the search token before the lookahead, in case of lookbehind we need to place the search token after the lookbehind. But i've also seen such a construct: (?=foo).
.Does that make sense and if so what will it match?
1 Answer
I've also seen (?=foo).
. Does that make sense and if so what will it match?
It's still a positive lookahead regexp:
Source regex101: Online regex tester and debugger
Notes:
If your test expression is
afoo
it will matchf
.To match
foo
use(?=foo).+
-
Ok but can You explain me how does such regex work? For e.g. having
afoo
test string how does the regex process the test string letters trying a match? Dec 27, 2017 at 12:27 -
@Ringger81 It matches a single character from the rexexp (that's what
.
means). See updated answer.– DavidPostill ♦Dec 27, 2017 at 12:35