fork download
  1. import re
  2.  
  3. pattern = r"~[^~#]*~|((?:(?!match-this).)*match-this(?:(?!match-this)[^#~])*)"
  4. s = "match-this~match-this~ match-this ~match-this#match-this~match-this~match-this"
  5. res = [m for m in re.findall(pattern, s) if m]
  6.  
  7. print (res)
Success #stdin #stdout 0.03s 9520KB
stdin
Standard input is empty
stdout
['match-this', ' match-this ', '~match-this', '#match-this', 'match-this']