fork download
  1. import re
  2. user_sentence = "hello \t how are you?"
  3. user_sentenceSplit = []
  4. for x in re.finditer(r"[^\S ]|[\w']+|[.,!?;]",user_sentence):
  5. if x.group() == "\t": # if it is a tab, replace the value
  6. user_sentenceSplit.append("tab")
  7. else: # else, push the match value
  8. user_sentenceSplit.append(x.group())
  9. print(user_sentenceSplit)
Success #stdin #stdout 0s 9024KB
stdin
Standard input is empty
stdout
['hello', 'tab', 'how', 'are', 'you', '?']