Positive lookbehind

Positive lookbehind matches the substring from a string if the defined pattern is preceded by the substring. Refer to the following example:

  • Consider the sentence: I play on the playground. It is the best ground.
  • Now you want to extract ground, if it is preceded by the string play. In this case, you can use positive lookbehind.

The syntax of positive lookbehind is (?<=pattern)

The regex r(?<=play)ground matches ground, but only if it is preceded by play.