python中文字符的編碼范圍是:
\u4e00-\u9fa5
使用正則匹配中文
#-*-coding:utf-8-*-
importre
'''
python3.5版本
正則匹配中文,固定形式:\u4E00-\u9FA5
'''
words='studyin山海大學(xué)'
regex_str=".*?([\u4E00-\u9FA5]+大學(xué))"
match_obj=re.match(regex_str,words)
ifmatch_obj:
print(match_obj.group(1))
結(jié)果:山海大學(xué)
以上內(nèi)容為大家介紹了python培訓(xùn)之如何匹配中文,希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓(xùn)機構(gòu):千鋒教育。