python如何匹配中文

图片[1]-python如何匹配中文-uusu优素-乐高,模型,3d打印,编程

中文字符的编码范围是:

\u4e00-\u9fa5
#-*-coding:utf-8-*-
importre
'''
python3.5版本
正则匹配中文,固定形式:\u4E00-\u9FA5
'''
words='studyin山海大学'
regex_str=".*?([\u4E00-\u9FA5]+大学)"
match_obj=re.match(regex_str,words)
ifmatch_obj:
print(match_obj.group(1))
结果:山海大学
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享