python中用给定字符去替换字符窜里的连续数字

导入python里面的re库:

re库:参考https://www.baidu.com/link?url=EA3rwK4-OqzdxibGNh2frOaruOe8WpFTXwTfEKgxKgKUH1GWx0RRrheJ5CmcXKHNAVZkUylm3WE0bPWpJqmJyq&wd=&eqid=82400b2d000422ae000000025c974ee7

代码:

import re

str='AAAA222SSS2345FFFFF'
str1=re.sub("\d+","gong", str)
print(str1)

输出:

AAAAgongSSSgongFFFFF

import re

str='AAAA222SSS2345FFFFF'
str1=re.sub("\d","gong", str)
print(str1)

输出:

AAAAgonggonggongSSSgonggonggonggongFFFFF

 

你可能感兴趣的:(python中用给定字符去替换字符窜里的连续数字)