200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python正则匹配中文_python 正则表达式匹配中文-阿里云开发者社区

python正则匹配中文_python 正则表达式匹配中文-阿里云开发者社区

时间:2020-12-12 05:15:50

相关推荐

python正则匹配中文_python 正则表达式匹配中文-阿里云开发者社区

python 正则表达式匹配中文

文件编码为 utf-8

设置默认编码为 utf-8

中文需要转换为 \u 形式的编码,也就是 编码,

轮换方法,cmd 下执行 python 进入 python 命令提示符模式

执行:

>>> u'中文'.encode('unicode_escape')

输出为:

'\\u4e2d\\u6587'

使用示例:

import sys

defaultencoding = 'utf-8'

if sys.getdefaultencoding() != defaultencoding:

reload(sys)

sys.setdefaultencoding(defaultencoding)

import itchat,time,re

from itchat.content import *

@itchat.msg_register([TEXT])

def text_reply(msg):

print(msg['Text'])

match = re.search(u'[\u5e74]',msg['Text'])

print(match)

if match:

itchat.send(('那我就祝您狗年大吉大利'), msg['FromUserName'])

@itchat.msg_register([PICTURE, RECORDING, VIDEO, SHARING])

def other_reply(msg):

itchat.send(('那我就祝您狗年大吉大利'), msg['FromUserName'])

itchat.auto_login(enableCmdQR=True,hotReload=True)

itchat.run()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。