把内容过程中比较好的一些内容段备份一下,如下内容段是关于python正则表达式match、search使用实例的内容,应该能对各朋友也有用途。
import re
def testsearchandmatch():
s1=“helloworld, i am 30 !”
w1 = “world”
m1 = re.search(w1, s1)
if m1:
print(“find : %s” % m1.group())
if re.match(w1, s1) == none:
print(“cannot match”)
w2 = “helloworld”
m2 = re.match(w2, s1)
if m2:
print(“match : %s” % m2.group())
testsearchandmatch()
#find : world
#cannot match
#match : helloworld