python determines whether a character string contains an instance of Chinese characters or non Chinese characters

  • 2021-07-18 08:27:28
  • OfStack

The value of compile in model can be changed as needed to meet different detection requirements


# Judge 1 Does the paragraph text contain simplified Chinese 
import re
zhmodel = re.compile(u'[\u4e00-\u9fa5]')  # Check Chinese 
#zhmodel = re.compile(u'[^\u4e00-\u9fa5]')  # Check non-Chinese 
contents = u' ( 2014 ) Shennan French people 2 Initial word 280 No. '
match = zhmodel.search(contents)
if match:
  print(contents)
else:
  print(u' Chinese is not included ')

Related articles: