擅长:python、mysql、java
<p>你不需要使用正则表达式。使用<a href="https://docs.python.org/3/library/stdtypes.html#str.partition" rel="nofollow">^{<cd1>}</a>:</p>
<pre><code>>>> line = 'jero, kor@gmail.com, 44d448e4d, team, 0, 6, 5, 2, s, s, s, none, none'
>>> a, sep, _ = line.partition('team')
>>> a
'jero, kor@gmail.com, 44d448e4d, '
>>> sep
'team'
>>> a + sep
'jero, kor@gmail.com, 44d448e4d, team'
</code></pre>
<hr/>
^{pr2}$
<p><strong>更新</strong></p>
<p>要解决@DSM提到的问题:在包含<code>team</code>的其他字段上拆分:</p>
<pre><code>with open('file.txt') as f:
for line in f:
a, sep, _ = line.partition(', team,')
line = a + sep
# Do something with line
</code></pre>