[Regex] Lookarounds

  • Positive lookahead
Regex: \d+(?=apples)
String: "666apples"
Match: "666"
  • Negative lookahead
Regex: \d+(?!apples)
String: "666bananas"
Match: "666"
  • Positive lookbehind
Regex: (?<=apples)\d+
String: "apples666"
Match: "666"
  • Negative lookbehind
Regex: (?<!apples)\d+
String: "bananas666"
Match: "666"