fork(1) download
  1. # http://stackoverflow.com/q/33115720/5290909
  2. import re
  3.  
  4. pattern = re.compile(r'(?<![-\w])\w+(?:-\w+)+(?![-\w])')
  5. text = "-abc word semi-column peace -not-wanted- one-word dont-match- multi-hyphenated-word"
  6.  
  7. result = re.findall(pattern, text)
  8.  
  9. print(result)
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
['semi-column', 'one-word', 'multi-hyphenated-word']