高级特性-正则表达式

前端之家收集整理的这篇文章主要介绍了高级特性-正则表达式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. re.search(pattern,string,flag)

与re.match()不同,匹配整个字符串,match如果开始不匹配则返回none

2. re.sub替换

re.sub(pattern,replace,string)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/python
import re
#re.subfunctiontesting
phone = "Catsaresmarterthandogs"
number = re.sub( '\D' ,"",phone)
print (number)
#re.searachfunctiontesting
#caution:spaceintheregex
matchObj re.search( "(.*)are(.*?).*" if matchObj:
(matchObj.groups())
原文链接:https://www.f2er.com/regex/360860.html

猜你在找的正则表达式相关文章