fork download
  1. # http://stackoverflow.com/q/33205876/5290909
  2. import re, string
  3.  
  4. text = "ABC-_-12345..::()"
  5.  
  6. punctuation = re.sub( r'([-\]\\])', r'\\\1', string.punctuation)
  7. pattern = '[0-9]+|[a-zA-Z]+|[%s]+' % punctuation
  8.  
  9. result = re.findall( pattern, text)
  10. print(result)
  11.  
  12. # => ['ABC', '12345', '..::()']
Success #stdin #stdout 0.03s 10344KB
stdin
Standard input is empty
stdout
['ABC', '-_-', '12345', '..::()']