擅长:python、mysql、java
<p>按照与<code>re.split()</code>匹配的正则表达式的降序,枚举所有较小的事例:</p>
<pre class="lang-py prettyprint-override"><code>import re
s = "a paper with some letters, a torn leaf and clock and an angel doll"
re.split(r'^an |^a |^the |, and a |, and an |, and the |, and |, and an |, an |, the |, a | and an | and | an | the', s)
# ['', 'paper with some letters', 'torn leaf', 'clock', 'angel doll']
</code></pre>
<p>剩下的只是清理<code>''</code>,以此类推。你知道吗</p>
<p>要保留匹配的内容,请将正则表达式用括号括起来,如文档所示:</p>
<pre class="lang-py prettyprint-override"><code>re.split(r'(^an |^a |^the |, and a |, and an |, and the |, and |, and an |, an |, the |, a | and an | and | an | the )', s)
# ['', 'a ', 'paper with some letters', ', a ', 'torn leaf', ' and ', 'clock', ' and an ', 'angel doll']
</code></pre>