Jump to content

Regex and cyrillic


yaxar

Recommended Posts

I am trying to check if a string is Cyrillic

but so far it is not working.

This is my code so far.

$str = 'ырөлоырөб';
if  (preg_match('{Script=Cyrillic}/iu*', $str)) {
echo 'it works';
}else {
echo 'it dosent work';
}

When i tried it on my server it outputed 'it dosent work'.

can you help me and find if their is anything wrong with the regex expression.

Thanks

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/
Share on other sites

The comments here look relevant (see below in the responses where someone discusses PHP and Cyrillic): http://stackoverflow.com/questions/4907342/javascript-regexp-cyrillic-pattern

 

Also are you sure your cyrillic string is encoded in UTF8 when it goes into the preg_match()?

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188524
Share on other sites

The comments here look relevant (see below in the responses where someone discusses PHP and Cyrillic): http://stackoverflow.com/questions/4907342/javascript-regexp-cyrillic-pattern

The regex expression they gave there "[\s\p{IsCyrillic}]" outputs an error

Message: preg_match() [function.preg-match]: Compilation failed: unknown property name after \P or \p at offset 15

Also are you sure your Cyrillic string is encoded in UTF8 when it goes into the preg_match()?

And yes it is be Cyrillic.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188588
Share on other sites

According to the comments on that site it's \p{Cyrillic}, and it will only work if PHP was compiled with a regexp library which supports that.

 

But you can still do it like this:

 

$pattern = "/[абвгдАБВГД]/";
preg_match($pattern, $str);

 

And if you list every possible cyrillic character in there, it'll work..

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188855
Share on other sites

  • 4 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.