2024-04-24 07:18:06 发布
网友
请帮忙处理这个案子:
m = re.split('([A-Z][a-z]+)', 'PeopleRobots') print (m)
结果:
为什么列表中有空元素?在
根据re.split documentation:
If there are capturing groups in the separator and it matches at the start of the string, the result will start with an empty string. The same holds for the end of the string:
如果要获得People和Robots,请使用re.findall:
People
Robots
>>> re.findall('([A-Z][a-z]+)', 'PeopleRobots') ['People', 'Robots']
可以省略分组:
根据re.split documentation:
如果要获得
People
和Robots
,请使用re.findall:可以省略分组:
^{pr2}$相关问题 更多 >
编程相关推荐