2012-12-07 101 views
0

如何獲取字符串中字符的第二次出現? 我想用它來從www.example.com/example/abc/aaa獲取字符串中字符的倒數第二次出現

+0

我注意到你有沒有接受任何答案...檢查了這一點,看看它是如何工作的:HTTP ://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Sheena

回答

0

得到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] 
相關問題