python中的re模块

时间:2022-01-18 03:21:10

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