- Python Natural Language Processing
- Jalaj Thanaki
- 92字
- 2025-02-28 13:05:45
Positive lookahead
Positive lookahead matches the substring from a string if the defined pattern is followed by the substring. If you don't understand, then let's look at the following example:
- Consider a sentence: I play on the playground.
- Now, you want to extract play as a pattern but only if it follows ground. In this situation, you can use positive lookahead.
The syntax of positive lookahead is (?=pattern)
The regex rplay(?=ground) matches play, but only if it is followed by ground. Thus, the first play in the text string won't be matched.