Python — check if a string contains Cyrillic characters

前端 未结 4 1953
一整个雨季
一整个雨季 2020-12-31 06:19

How to check whether a string contains Cyrillic characters?

E.g.

>>> has_cyrillic(\'Hello, world!\')
False
>>> has_cyrillic(\'Приве         


        
4条回答
  •  清酒与你
    2020-12-31 06:51

    regex supports Unicode properties, along with a few short forms.

    >>> regex.search(r'\p{IsCyrillic}', 'Hello, world!')
    >>> regex.search(r'\p{IsCyrillic}', 'Привет, world!')
    
    >>> regex.search(r'\p{IsCyrillic}', 'Hello, wёrld!')
    
    

提交回复
热议问题