I’m reading through the Javascript RegExp documentation and noticed that the regex feature x(?=y) is not needed because you could just write x(?:y) and it would do exactly the same thing.
It would match x only if followed by y and would not capture y in the results.
Am I wrong? Is there a difference to the two?
The
(?=)is a “X, via zero-width positive lookahead”. The(?:)is a non-capturing group.Depending upon which methods you’re using the regular expression with (match vs. find, etc.), the results matched with the positive lookahead may not be included in your match result, where the non-capturing group would still be included in the
[0]group on the match result.