0

如何获得字符串中字符的倒数第二个出现?我想用它来aaa获取www.example.com/example/abc/aaa

4

1 回答 1

0

我喜欢正则表达式:

import re
p = re.compile('a')
all_positions = [oMatch.span() for oMatch in p.finditer(sText)]
second_last_position_span = all_positions[-2]   
second_last_position_start_index = second_last_position_span[0]
于 2012-12-08T06:32:14.267 回答