preg_match UTF-8 issue

Go To


preg_match("/\b(word1|word2)\b/iu", 'text text text word1 text text');

For some reason the above code doesn't work with Hebrew characters on one server, but does work on another one. What could be the cause?

2012-04-04 20:42
by Lior


Do you have perl compatible regular expressions (PCRE) with unicode properties support enabled? that would be my guess.

2012-04-04 20:45
by Barry Chapman
To find out, at your shell - type pcretest -C and it will tell you if you have unicode properties support enabled - Barry Chapman 2012-04-04 20:45
Compiled with UTF-8 support Unicode properties suppor - Lior 2012-04-04 20:49
On both servers - Barry Chapman 2012-04-04 20:51
Sorry for my ignorance, but how would I check this on a Windows WAMP installation - Lior 2012-04-04 20:59


You need Perl Compatible Regular Expression (PCRE) version 3.9 at least on your server to be able to have UTF-8 characters in pattern with preg_match() function

2013-08-11 13:51
by Trix


try preg_match("/\b(word1|word2)\b/iu", utf8_decode('text text text word1 text text'));

2012-04-04 20:45
by Pedro Papadópolis
that is not going to solve the problem - Barry Chapman 2012-04-04 20:46