fork download
  1. import re
  2.  
  3. s = """limk ab1
  4. limk ab2 helo
  5. rest helo
  6. ab3 limk helo
  7. ab4 limk"""
  8.  
  9. matches = [x[0] if x[0] != '' else x[1] for x in re.findall(r'(?m)^([0-9a-zA-Z]{3})\s+limk$|^limk\s+([0-9a-zA-Z]{3})$', s)]
  10. for match in matches:
  11. print(match)
Success #stdin #stdout 0.02s 9756KB
stdin
Standard input is empty
stdout
ab1
ab4