fork download
  1. import re
  2. rx = re.compile( r' *(?:\b(?<!-)\w+-\B|\B-\w+\b(?!-))' )
  3. text = 'here are -some- word sub-words -word1 word2- sub-word2 word3- -word4\n-word5 example\nword6-\nword7-\nanother one -word8\n-word9'
  4. print( rx.sub('', text) )
Success #stdin #stdout 0.04s 9584KB
stdin
Standard input is empty
stdout
here are -some- word sub-words sub-word2
 example


another one