擅长:python、mysql、java
<pre><code>import re
split = re.findall(r"[\w']+|[.,!?;]", "How are you?")
print(split)
</code></pre>
<hr/>
<p><strong>输出:</strong></p>
^{pr2}$
<hr/>
<p><a href="http://ideone.com/xHt2l2" rel="nofollow">Ideone Demo</a></p>
<p><a href="https://regex101.com/r/bW3xS6/1" rel="nofollow">Regex101 Demo</a></p>
<hr/>
<p><strong>正则表达式说明:</strong></p>
<pre><code>"[\w']+|[.,!?;]"
1st Alternative: [\w']+
[\w']+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\w match any word character [a-zA-Z0-9_]
' the literal character '
2nd Alternative: [.,!?;]
[.,!?;] match a single character present in the list below
.,!?; a single character in the list .,!?; literally
</code></pre>