fork download
  1. import re
  2.  
  3. def begin_end_hyphen_removal(line):
  4. return re.sub(r"\s*(?<!\S)(?:-\w+(?:-\w+)*|\w+(?:-\w+)*-)(?!\S)", "", line)
  5.  
  6.  
  7. s = ("here are some word sub-words -word1 word2- sub-word2 word3- -word4\n"
  8. "-word5 example\n"
  9. "word6-\n"
  10. "word7-\n"
  11. "another one -word8\n"
  12. "-word9")
  13. print(begin_end_hyphen_removal(s))
Success #stdin #stdout 0.02s 9336KB
stdin
Standard input is empty
stdout
here are some word sub-words sub-word2 example
another one