python re.sub

用法:

re.sub(pattern, repl, string)

将string中符合pattern的部分用repl替代。

import re
text = "hello this is test 123, 122 1333399999."
re.sub("d{3}", "zzz", text)  # text 中,符合“d{3}”的部分替换为“zzz”

# output:'hello this is test zzz, zzz zzzzzzzzz9.'
原文地址:https://www.cnblogs.com/buxizhizhoum/p/8631897.html