fork(1) download
  1. import re
  2.  
  3. pattern = r"\s+|(?<=\s)'|'(?=\s)|(?<=\w)([,.!?])"
  4. words = """hello my name is 'joe.' what's your's"""
  5. result = [s for s in re.split(pattern, words) if s]
  6. print(result)
Success #stdin #stdout 0.02s 9524KB
stdin
Standard input is empty
stdout
['hello', 'my', 'name', 'is', 'joe', '.', "what's", "your's"]