正则替換
特殊字符:\.^$?+*{}[]()|
re.search 全文一次搜索到停止
re.match 全文開頭一次搜索停止
def sub_once_a_time(pattern, raw_str):
before_str = "0"
after_str = raw_str
sub_list = []
count_sub = 1
while after_str != before_str:
before_str = after_str
repl_str = "sub_" + str(count_sub)
value = re.search(pattern, before_str)
after_str = re.sub(pattern, repl_str, before_str, count=1)
sub_list.append({repl_str: value})
count_sub += 1
return sub_list

浙公网安备 33010602011771号