What is the difference between (?: ) and (?= ) I assume that the first returns the text that it matches in a match function (but doesn’t when applied to a sub expression group number, but not sure if I am right. Thank in advance 🙂 I know what they are used for, but I am not sure how they act differently. Also can repetition characters be applied to look ahead assertions?
What is the difference between (?: ) and (?= ) I assume that the
Share
So the thing about both of these constructs is that the don’t return anything.
(?: ... )is used the same way as ordinary( ... )except that its result is not captured and not returned. In Perl, and I believe in Javascript, this can lead to faster performance due to the Regex engine not having to remember the matched substrings.The idea of
(?= )is different. You can think of any component of a regex as sort of “eating up” some subset of the matched string. But not with(?= ). Another way to think of it is that whatever comes after the(?= )matches at the exact same place in the string that the(?= )itself matches, not after the end of it like a normal group.