Positive Lookahead is a zero-length assertion used in Regular Expressions (RegEx). What this means is that it looks forward in the string to see if there is a match, but it doesn't consume the match. To use this tag, the question must be about RegEx where the main focus is on Positive Lookahead. The programming language used to execute RegEx should be mentioned as well.
Regular Expressions is checking a string to see if it matches a pattern. Positive Lookahead is a pattern that looks forward in the string to see if there is a match, but it doesn't consume the match, so it is regarded as a zero-length assertion. For example, if one wishes to check in a string to see if the character 'a' is followed by the character 'b', then the pattern would be
a(?=b)
This pattern would match:
- about
- absolute
- fabulous
but wouldn't match
- anything
- band
The lookahead can be any amount of characters or a regex pattern. Expanding on the previous example:
a(?=bo)
This pattern would match:
- about
but wouldn't match
- absolute
- fabulous
Since Positive Lookahead doesn't consume the match, to store the match place capturing parenthesis around the lookahead pattern, like so:
a(?=(bo))
The lookahead match is then stored for retrieval.
References