1.所谓组。您检查一次,你可以选择多个比赛结果,每个结果是指一组
eg.
import repattern = re.compile(r'
>)(.*?)</div>') match = pattern.match('<div class="test">Hello <div>wa haha<div>test xxx</div></div>world</div>') if match: print match.group(2) print match.group(1) print match.group(0) >>> ================================ RESTART ================================ >>> Hello <div>wa haha<div>test xxx class="test"> <div class="test">Hello <div>wa haha<div>test xxx</div> >>>
当中group(0)比較特殊,全部组的合集2.查找一个文件里全部的http(url)地址
import reimport urllib2f = open('url.txt','r')string = ""while 1: line = f.readline() if not line:break string += linef.close()urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', string)3.正则表达式空格含有\t\r\n\f\v如几个字符
版权声明:本文博客原创文章,博客,未经同意,不得转载。