fork download
  1. import re
  2. foo = "this is IMP Y text\nand this is also IMP1 Y text\nthis is not so IMP2 N text\nY is not important"
  3. print(re.findall(r'\w+(?=[^\S\r\n]+Y\b)', foo))
Success #stdin #stdout 0.02s 9392KB
stdin
Standard input is empty
stdout
['IMP', 'IMP1']