Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Russian / cyrillic in Javascript string?

I'm trying to detect if a string contains Russian (cyrillic) characters or not. I'm using this code:

term.match(/[\wа-я]+/ig);

but it doesn't work – or in fact it just returns the string back as it is.

Can somebody help with the right code?

Thanks!

like image 257
Aerodynamika Avatar asked Nov 10 '14 15:11

Aerodynamika


1 Answers

Perhaps you meant to use the RegExp test method instead?

/[а-яА-ЯЁё]/.test(term)

Note that JavaScript regexes are not really Unicode-aware, which means the i flag will have no effect on anything that's not ASCII. Hence the need for spelling out lower- and upper-case ranges separately.

like image 127
Joey Avatar answered Sep 18 '22 10:09

Joey