Python正则表达式re模块常用方法与实例应用.pdfVIP

  • 2
  • 0
  • 约1.67千字
  • 约 1页
  • 2026-04-14 发布于北京
  • 举报

Python正则表达式re模块常用方法与实例应用.pdf

一:

从下面的字符串提取中号(只要号)

Str=1*5*1*1*0*3*3*6*4*9*1#发来的

#coding=utf-8

importre

str=1*5*1*1*0*3*3*6*4*9*1#发来的

#deletepython-stylecomments

num=re.sub(r#.*$,,str)

printphonenum:,num

#Removeanythingotherthandigits

num=re.sub(r\D,,str)

printPhoneNum:,num

二:了解re模块的常用方法:

Match,search,split,findall,sub的区别

1.match(string[,pos[,endpos]])|re.match(pattern,string[,flags]):

这个方法将从string的pos下标处起尝试匹配pattern;如果p

文档评论(0)

1亿VIP精品文档

相关文档