窃以为,模式匹配在将来利用Python做爬虫的时候会比较有用。
模式匹配需要导入re模块。
下面就是一段模式匹配
import re
match=re.match('hello[\t]*(.*)world','hello python world')
match.group(1)
这段代码的作用就是用re模块中的match方法来找到hello和world中间的字符。
再比如下一段
import re
re.match('/(.*)/(.*)/(.*)/','/ss/sss/ss/')
match.groups()
这段代码的作用就是找到斜杠中间的字符串。