这是我的字符串:
'C. AndersonN. ChubbD. ForemanT. GurleyM. IngramA. JonesJ. Richard'
我想使用正则表达式对大写字母+句点进行分割以生成如下列表:
['C. Anderson', 'N. Chubb', 'D. Foreman', 'T. Gurley', 'M. Ingram', 'A. Jones', 'J. Richard']
谢谢!
答案 0 :(得分:5)
您可以使用re.findall代替更简单的正则表达式:
import re
s = 'C. AndersonN. ChubbD. ForemanT. GurleyM. IngramA. JonesJ. Richard'
new_s = re.findall('[A-Z]\.\s[A-Z][a-z]+', s)
输出:
['C. Anderson', 'N. Chubb', 'D. Foreman', 'T. Gurley', 'M. Ingram', 'A. Jones', 'J. Richard']