网络编程
位置:首页>> 网络编程>> Python编程>> python 判断字符串中是否含有汉字或非汉字的实例

python 判断字符串中是否含有汉字或非汉字的实例

作者:多动脑,多动手  发布时间:2022-07-01 11:25:59 

标签:python,字符串,汉字,非汉字

model中compile值可以根据需要更改,满足不同的检测需求


#判断一段文本中是否包含简体中文
import re
zhmodel = re.compile(u'[\u4e00-\u9fa5]')  #检查中文
#zhmodel = re.compile(u'[^\u4e00-\u9fa5]')  #检查非中文
contents = u'(2014)深南法民二初字第280号'
match = zhmodel.search(contents)
if match:
 print(contents)
else:
 print(u'没有包含中文')

来源:https://blog.csdn.net/wu1yr/article/details/81630494

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com