>>> origin = "hello alex bcd alex lge alex acd 19"
>>> r=re.sub("a\w+","999",origin,2)
>>> r
'hello 999 bcd 999 lge alex acd 19'
“a\w+”:表示匹配以a开头的单词
"999":表示替换成的值
origin:原始字符串
2:只匹配2个
标签:origin,alex,19,python,acd,999,lge,re,模块
来源: https://www.cnblogs.com/gaoyuxia/p/10642953.html