某些特殊部分的正则表达式问题

You*_*ung 0 php regex

当我尝试使用以下代码查找某些字符时出现问题:

$str = "??????????Q??,??q??287?7?1??7?,??63??????,?1??hell????o?w??or?d!??????????????? | ??????EXCEL";
preg_match_all('/[\w\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A]/',$str,$match); //line 5
print_r($match);
Run Code Online (Sandbox Code Playgroud)

我收到的错误如下:

Warning: preg_match_all() [function.preg-match-all]: Compilation failed: PCRE does not  support \L, \l, \N, \U, or \u at offset 4 in E:\mycake\app\webroot\re.php on line 5
Run Code Online (Sandbox Code Playgroud)

我对reg表达并不熟悉,也不知道这个错误.我怎么能解决这个问题?谢谢.

Ste*_*rig 6

问题是,PCRE正则表达式引擎不理解\uXXXX-syntax通过其unicode代码点表示字符.相反,PCRE引擎使用\x{XXXX}-syntax与-modifier结合使用u:

preg_match_all('/[\w\x{FF10}-\x{FF19}\x{FF21}-\x{FF3A}\x{FF41}-\x{FF5A}]/u',$str,$match); 
print_r($match);
Run Code Online (Sandbox Code Playgroud)

见我的答案在这里的一些更多的信息.

编辑:

$str = "??????????Q??,??q??287?7?1??7?,??63??????,?1??hell????o?w??or?d!??????????????? | ??????EXCEL";
preg_match_all('/[\w\x{FF10}-\x{FF19}\x{FF21}-\x{FF3A}\x{FF41}-\x{FF5A}]/u',$str,$match);
//                                                                       ^
//                                                                       |
print_r($match);
/* Array
(
    [0] => Array
        (
            [0] => ?
            [1] => Q
            [2] => q
            [3] => 2
            [4] => 8
            [5] => 7
            [6] => 7
            [7] => 1
            [8] => 7
            [9] => 6
            [10] => 3
            [11] => 1
            [12] => h
            [13] => e
            [14] => l
            [15] => l
            [16] => o
            [17] => w
            [18] => o
            [19] => r
            [20] => d
            [21] => E
            [22] => X
            [23] => C
            [24] => E
            [25] => L
        )

) */
Run Code Online (Sandbox Code Playgroud)

您确定,您使用了u-modifier(参见上面的箭头)?如果是这样,你必须检查你的PHP是否支持th- umodifier(Unix上的PHP> 4.1.0,Windows上的> 4.2.3).