python内置模块之re模块

#re.match从头开始匹配
#re.search匹配包括
#re.findall把所有匹配的字符放到以列表中的元素返回
#re.sub匹配并替换
import re
a=re.split("\d","a123df8")#re.split就是以什么分割,并用str形式以列表的元素返回,替换的变成空字符
print(a)
b=re.sub("\d","*","adff158f4df1eg4",count=5)#前面是要替换的,接着是替换成什么,然后是替换目标,最后是替换多少次。默认全部
print(b)
       
       
       
       
       
       
       
       
       
       
       
       

参考:https://www.cnblogs.com/tina-python/p/5508402.html

猜你喜欢

转载自blog.csdn.net/qq_37181884/article/details/81877911