fork download
  1. import re
  2. rx = r"\S+(?:[^\S\r\n]+\S+){0,3}(?=[^\S\r\n]+color\b)"
  3. s = "it is amamzing to look at the evening sky and the color\ncolor of the sky is blue\ncolor\nsky color is blue"
  4. print(re.findall(rx, s))
Success #stdin #stdout 0.01s 7108KB
stdin
Standard input is empty
stdout
['evening sky and the', 'sky']