二,re模块操做正则表达式
在Python中须要经过正则表达式对字符串进行匹配的时候,能够使用一个模块,名字为re编辑器
#coding=utf-8 # 导入re模块 import re # 使用match方法进行匹配操做 result = re.match(正则表达式,要匹配的字符串) # 若是上一步匹配到数据的话,能够使用group方法来提取数据 result.group()
#coding=utf-8 import re result = re.match("itcast","itcast.cn") result.group()
运行结果为:itcast
ide
e.match() 可以匹配出以xxx开头的字符串spa