fork download
  1. import re
  2. pattern = r"\s+\w+\s?(?::|\(\s*([^()]+)\s*\)|\[\s*([^]\[]+)\s*])\s*"
  3. items = [
  4. ";or, art1 : art2 art3",
  5. ";or, art1 ( art2 art3 )",
  6. ";or, art1 [ art2 art3 ]",
  7. "SAD; Happy; ING:train coca",
  8. "SAD; Happy; ING(train coca)",
  9. "SAD, Happy, ING[train coca]"
  10. ]
  11.  
  12. for item in items:
  13. print(re.sub(pattern, r' \1\2', item))
Success #stdin #stdout 0.02s 9608KB
stdin
Standard input is empty
stdout
;or, art2 art3
;or, art2 art3 
;or, art2 art3 
SAD; Happy; train coca
SAD; Happy; train coca
SAD, Happy, train coca