fork download
  1. import re
  2.  
  3. word_list=['word', 'kap1', 'another word', 'abc-123', 'another-1 word', 'another word 1']
  4.  
  5. reg = re.compile(r'^([a-zA-Z]+)([- ]?)([0-9]+)$')
  6.  
  7. for w in word_list:
  8. m = reg.match(w)
  9. if m:
  10. result = []
  11. seps = ['', ' ', '-']
  12. seps.remove(m.group(2))
  13. for s in seps:
  14. result += [m.group(1) + s + m.group(3)]
  15. print result
Success #stdin #stdout 0s 23352KB
stdin
Standard input is empty
stdout
['kap 1', 'kap-1']
['abc123', 'abc 123']