fork download
  1. import re
  2.  
  3. pattern = r"\bage(?:(?:(?!\b(?:height|weight)\b)[^<>])*[<>]\s+\d+)+"
  4. s = ("age > 10 but can be > 20 or > 22 - if the height is > 60 then age can be > 30, otherwise it must be < 35\n")
  5.  
  6. for m in re.findall(pattern, s):
  7. print(re.findall(r"([<>])\s+(\d+)", m))
Success #stdin #stdout 0.03s 9480KB
stdin
Standard input is empty
stdout
[('>', '10'), ('>', '20'), ('>', '22')]
[('>', '30'), ('<', '35')]