pzakutansky
pzakutansky

Reputation: 23

JavaScript regexp not working in PHP

I have this regexp working correctly in JavaScript (white space in the beginning):

 *\u002D *| *\u003A *| *\u002C *| *\u002F *| *\u2012 *| *\u2013 *| *\u2014 *| *\u2015 *| *\u2018 *| *\u2019 *| *\u0022 *| *\u0027 *

It replaces some unicode characters (dashes, colons, apostrophes etc.) also with white spaces around with just one white space, for example "word: word - word" will be "word word word". So I'm trying to remove some specific unicode chars from string.

Now I need to use this regexp in PHP. I know that single unicode char should look like this in PHP regexp: \x{xxxx} so my new regexp looks like this and it's not working at all...

/ *\x{002D} *| *\x{003A} *| *\x{002C} *| *\x{002F} *| *\x{2012} *| *\x{2013} *| *\x{2014} *| *\x{2015} *| *\x{2018} *| *\x{2019} *| *\x{0022} *| *\x{0027} */

Upvotes: 1

Views: 178

Answers (1)

Jon
Jon

Reputation: 437386

As long as you use the /u modifier for the regular expression it should work fine.

Example with the Greek capital letter phi:

echo preg_match('/\x{03a6}/u', 'Φ');

Upvotes: 2

Related Questions