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()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值