import re
pattern = re.compile(r"\$\{not_exited_tel\}")
regname_pattern = re.compile(r"\$\{regname\}")
def not_exited_tel_replace(data):
if re.search(pattern, data):
data = re.sub(pattern, "18912345678", data)
if re.search(regname_pattern, data):
data = re.sub(regname_pattern, "apple", data)
return data
if __name__ == '__main__':
target_str1 = '{"mobilephone": "${not_exited_tel}", "pwd": "123456", "regname": "${regname}"}'
target_str2 = '{"mobilephone": "${not_exited_tel6}", "pwd": "6789", "regname": "orange"}'
target_str3 = '{"mobilephone": , "pwd": "1234567890123456789", "regname": "${regname}"}'
print(not_exited_tel_replace(target_str1))
print(not_exited_tel_replace(target_str2))
print(not_exited_tel_replace(target_str3))