Artificial intelligent assistant

正規表現に合致した特定の文字のみを置換したい a1 = "Extension=1200,Type=567,Port=S123,Name= **Suzuki, Taro** ,Coverage_Path_1=,Coverage_Path_2=" b1 = "Extension=3089,Type=123,Port=S432,Name= **OPS_Temp** ,Coverage_Path_1=,Coverage_Path_2=" [Name][,Coverage_Path_1],,_ a1= "Extension=1200,Type=567,Port=S123,Name=Suzuki_Taro,Coverage_Path_1=,Coverage_Path_2=" b1 = "Extension=3089,Type=123,Port=S432,Name=OPS_Temp,Coverage_Path_1=,Coverage_Path_2=" pattern =r"\w*,+\s\w*" for l in (a1, b1): if re.search(pattern, l): print(re.findall(pattern, l))

import re

a1 = "Extension=1200,Type=567,Port=S123,Name=Suzuki, Taro,Coverage_Path_1=,Coverage_Path_2="
b1 = "Extension=3089,Type=123,Port=S432,Name=OPS_Temp,Coverage_Path_1=,Coverage_Path_2="

print(re.sub(r'(Name.*?)(,+\s)(.*?,Coverage_Path_1)', r'\1_\3', a1))
print(re.sub(r'(Name.*?)(,+\s)(.*?,Coverage_Path_1)', r'\1_\3', b1))

#
Extension=1200,Type=567,Port=S123,Name=Suzuki_Taro,Coverage_Path_1=,Coverage_Path_2=
Extension=3089,Type=123,Port=S432,Name=OPS_Temp,Coverage_Path_1=,Coverage_Path_2=

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 1bbb6b554b4ace045b23c57b4b8f3b4b