2018年10月26日 星期五

python 正則取代

import re

reg_1 = re.compile(r"(\d)")
print(reg_1)

str_1 = "The population of 298444215 is growing"

res = reg_1.sub(r"\1a", str_1)

print(res)