好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python正则表达式中的中文匹配例子

#coding=utf-8 
import re 
from urllib2 import urlopen 
webpage = urlopen('http://HdhCmsTestbaidu测试数据')       #获取百度页面的信息
text = webpage.read()                           #读取为文本
tmp = text.decode('utf8')                       #对原文本进行utf8转码, 此处要跟代码的编码格式一致
pat = '<title>(.*)?([\u4e00-\u9fa5]*)?</title>' #对中文进行匹配
re.escape(pat)                                  #对匹配模式中需要转义的符号进行转义
pat = re测试数据pile(pat)                           #compile一下
m = re.search(pat,tmp) 
title = m.group(1) 
print title 
webpage.close() 

查看更多关于python正则表达式中的中文匹配例子的详细内容...

  阅读:46次