简体   繁体   English

JavaScript正则表达式在PHP中不起作用

[英]JavaScript regexp not working in PHP

I have this regexp working correctly in JavaScript (white space in the beginning): 我有这个正则表达式在JavaScript中正常工作(开头是空白):

 *\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". 它用周围只有一个空格的空格替换了一些unicode字符(破折号,冒号,撇号等),例如“单词:单词-单词”将是“单词单词word”。 So I'm trying to remove some specific unicode chars from string. 所以我试图从字符串中删除一些特定的Unicode字符。

Now I need to use this regexp in PHP. 现在,我需要在PHP中使用此regexp。 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... 我知道单个unicode char在PHP regexp中应该是这样的:\\ x {xxxx},所以我的新regexp看起来像这样,并且根本不起作用...

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

As long as you use the /u modifier for the regular expression it should work fine. 只要对正则表达式使用/u修饰符,它就可以正常工作。

Example with the Greek capital letter phi : 希腊大写字母phi的 示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM