-
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(.*?).*"
(matchObj.groups())
|