用法:

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.'

 

posted on 2018-03-23 18:02  Go_Forward  阅读(98)  评论(0编辑  收藏  举报