How to check whether a string contains Cyrillic characters?
E.g.
>>> has_cyrillic('Hello, world!')
False
>>> has_cyrillic('Привет, world!')
True
You can use a regular expression to check if a string contains characters in the а-я, А-Я
range:
import re
def has_cyrillic(text):
return bool(re.search('[а-яА-Я]', text))
Alternatively, you can match the whole Cyrillic script range:
def has_cyrillic(text):
return bool(re.search('[\u0400-\u04FF]', text))
This will also match letters of the extended Cyrillic alphabet (e.g. ё, Є, ў).