I am trying to understand the positive look ahead regex. I have been following the official website
For a string "quit"
q(?=u)
This matches q in the string. But below does not matches anything
q(?=u)i
I can see the below explanation is given on the official website
Let's take one more look inside, to make sure you understand the implications of the lookahead. Let's apply q(?=u)i to quit. The lookahead is now positive and is followed by another token. Again, q matches q and u matches u. Again, the match from the lookahead must be discarded, so the engine steps back from i in the string to u. The lookahead was successful, so the engine continues with i. But i cannot match u. So this match attempt fails. All remaining attempts fail as well, because there are no more q's in the string.
I want to understand why/how is this not working. Or what this second regex even implies.
What does the below mean ?
Again, the match from the lookahead must be discarded, so the engine steps back from i in the string to u
I know lookahead is discarded and it is only used for matching(non capturing group). But what about the thing after the comma(,), I am not understanding what it is.
And this
The lookahead was successful, so the engine continues with i. But i cannot match u.
Why i is trying to match u ??
This is not a duplicate question as I am trying to understand a special case here rather than understanding what positive look ahead is. Kindly read the full question first before marking it as duplicate
I am trying to understand how or why is this failing
q(?=u)i