我想获取任何字符串中第二个大写字母的索引。
例如,在字符串"保罗喜欢冰淇淋"我想获得" I"的索引,它是11.它应该适用于任何字符串。
答案 0 :(得分:0)
您可以使用:
m = re.search(r'^([^A-Z]*[A-Z]){2}', 'Paul likes Ice cream.');
print m.span()[1]
12
答案 1 :(得分:0)
像
这样的东西>>> string = " Paul likes Ice cream."
>>> [ match.start() for match in re.finditer ("[A-Z]", string) ][1]
12