Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何获得字符串中字符的倒数第二个出现?我想用它来aaa获取www.example.com/example/abc/aaa
aaa
www.example.com/example/abc/aaa
我喜欢正则表达式:
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]