>>> 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 = "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个