fork download
  1. import re
  2. example_string = "; One, one; Two, two; Three, three; Four, four"
  3. desired_output = ["One, o", "Two, t", "Three, t", "Four, f"] #list output is OK
  4.  
  5. def findStringsInMiddle(a, b, text):
  6. return re.findall(re.escape(a)+"(.*?"+re.escape(b) + r"(?:\s*.)?)",text, flags=re.S)
  7.  
  8. desired_output = findStringsInMiddle('; ' , ',' , example_string)
  9. print(desired_output)
Success #stdin #stdout 0.02s 9440KB
stdin
Standard input is empty
stdout
['One, o', 'Two, t', 'Three, t', 'Four, f']