fork download
  1. import re
  2.  
  3. rx = re.compile(r"^(?:limk\s+([a-zA-Z0-9]{3})|([a-zA-Z0-9]{3})\s+limk)$", re.M)
  4. s = "limk ab1\nlimk ab2 helo\nrest helo\nab3 limk helo\nab4 limk"
  5. print (["{}{}".format(x,y) for x,y in rx.findall(s)])
  6.  
  7.  
Success #stdin #stdout 0.02s 9508KB
stdin
Standard input is empty
stdout
['ab1', 'ab4']