yakczh_cu 发表于 2015-08-18 14:34

正则表达式中有中文,是不是必须要转码?

# -*- encoding=utf8 -*-
import re

# pattten=re.compile('*人*')
patten=re.compile(u'人'.encode('utf8'))

message = u'some abd 123 人民'.encode('utf8')
print(re.search(patten, message).group())
正则中直接写中文提示raise error("nothing to repeat")
sre_constants.error: nothing to repeat

patagonia2 发表于 2015-08-31 14:54

是必须要转码?
我对jaca不熟,还真不懂。
页: [1]
查看完整版本: 正则表达式中有中文,是不是必须要转码?