Replacing a \t with something in a list
<pre><code>&gt;&gt;&gt;user_sentence = "hello \t how are you?"
&gt;&gt;&gt;import re
&gt;&gt;&gt;user_sentenceSplit = re.findall(r"([\s]|[\w']+|[.,!?;])",user_sentence)
&gt;&gt;&gt;print user_sentenceSplit
</code></pre>

<p>I get <code>['hello', '\t', 'how', 'are', 'you', '?']</code></p>

<p>I don't know how to create any code that will replace the <code>'\t'</code> with <code>'tab'</code>.</p>

<p>I do not believe that replacing <code>\t</code> in the original string will ever work, you have two issues:</p>

<ul>
<li>Your code also outputs spaces as tokens, but you do not want to have them</li>
<li>The <code>\t</code> in between letters will become a part of a word token.</li>
</ul>

<p>So, you need to replace <code>[\s]</code> with <code>[^\S ]</code> pattern that matches any whitespace but a regular space (add more excluded whitespace symbols if necessary into the negated character class) and you need to iterate through all the tokens and check if a token is equal to a tab, and then replace it with <code>tab</code> value. So, the best is to use <code>re.finditer</code> and push the found values into a list variable, see sample code below:</p>

<pre><code>import re
user_sentence = "hello \t how are you?"
user_sentenceSplit = []
for x in re.finditer(r"[^\S ]|[\w']+|[.,!?;]",user_sentence):
    if x.group() == "\t": # if it is a tab, replace the value
        user_sentenceSplit.append("tab")
    else:  # else, push the match value
        user_sentenceSplit.append(x.group()) 
print(user_sentenceSplit)
</code></pre>

<p>See the <a href="https://ideone.com/sbn0Dp" rel="nofollow">Python demo</a></p>

python regex