例子,python re模块用正则匹配中文。
代码:
 
#!/usr/bin/env python
#coding=utf-8  
import re   
from urllib2 import urlopen # python urllib2模块
  
webpage = urlopen('http://www.baidu.com')       #获取百度页面的信息  
text = webpage.read()                           #读取为文本  
tmp = text.decode('utf8')                       #对原文本进行utf8转码, 此处要跟代码的编码格式一致  
pat = '<title>(.*)?([u4e00-u9fa5]*)?</title>' #对中文进行匹配  
re.escape(pat)                                  #对匹配模式中需要转义的符号进行转义  
pat = re.compile(pat)                           #compile一下  
m = re.search(pat,tmp)   
title = m.group(1)   
print title   
webpage.close() 
注意,在unicode中,中文是u4e00-u9fa5 。