0

I'm using such pattern to find cyrillic symbols in my text, but it is returning true on unicode currency symbols "₴" (ukrainian hryvnya) and "€" (euro)

$pat = '/.*[А-Яа-яёЁ].*/';
$res = preg_match($pat, $str);

What is the problem?

  • Not knowing too much about the Unicode order myself, is it possible that unicode currency symbol values exist between А-Я or between а-я? It seems unlikely, but worth a look? – Gareth Parker Nov 24 '14 at 11:21

1 Answers1

2

You should make your pattern unicode-aware with /u modifier:

$pat = '/.*[А-Яа-яёЁ].*/u';
$res = preg_match($pat, $str);

Quoting the doc:

u (PCRE_UTF8)

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8.

Demo. BTW, if you only check whether or not cyrillic letters are present in the string without doing anything on the match (and with the given code you do), you can drop .* parts from your pattern.

raina77ow
  • 103,633
  • 15
  • 192
  • 229