2

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 1

1

I've also seen (?=foo).. Does that make sense and if so what will it match?

It's still a positive lookahead regexp:

enter image description here

Source regex101: Online regex tester and debugger

Notes:

  • If your test expression is afoo it will match f.

  • To match foo use (?=foo).+

2
  • 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?
    – Ringger81
    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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .