fork download
  1. import re
  2.  
  3. s = "s1: foo, bar s1:x,y s2:hello, hi s3: bar, foo."
  4.  
  5. def findByPrefix(prefix, s):
  6. pattern = rf"\b{re.escape(prefix)}: ?(\w+(?:, ?\w+)*)"
  7. res = []
  8. for m in re.findall(pattern, s):
  9. res.append(re.split(", ?", m))
  10. return res
  11.  
  12. print(findByPrefix("s1", s))
Success #stdin #stdout 0.02s 9504KB
stdin
Standard input is empty
stdout
[['foo', 'bar'], ['x', 'y']]