Python正则匹配中文

来源:互联网 发布:php tp框架介绍 编辑:程序博客网 时间:2024/04/29 15:51
当我们使用正则表达式匹配字符串中的中文中文时会发现字符串明明有目标串却不能匹配的情况

<span style="font-size:18px;">re.match(r'今天', str):</span>
字符串确实存在‘今天‘,解决办法只需要将中文转换为Unicode就行了:

<span style="font-size:18px;">re.match(ur'今天', post_time):</span>

完美!

0 0