1

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} */
1
  • In your PHP source, have you escaped the backslashes? Can we see the actual PHP source you're using, and some sample text you're matching against? When you say "it's not working at all", I assume that means it finds no matches where it should match. Commented May 7, 2013 at 18:38

1 Answer 1

2

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', 'Φ');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.