Regular expression error: no ending delimiter

China☆狼群 提交于 2019-12-11 09:13:11

问题


I'm trying to execute this regular expression:

<?php
    preg_match("/^([^\x00-\x1F]+?){0,1}/", 'test string');
?>

But keep getting an error:

Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in /var/www/preg.php on line 6

I can't understand where it is coming from. I have an ending delimeter right there... I tried to change delimiter to other symbols and it didn't help.

I would appreciate your help on this problem.


回答1:


Like Gumbo said, preg_match is not binary safe.

Use instead:

preg_match("/^([^\\x{00}-\\x{1F}]+?){0,1}/", 'test string'));

This is the correct way to specify Unicode code points in PCRE.




回答2:


I guess PHP chokes on the NULL character that denotes the end of a string in C.

Try it with single quotes so that \x00 is interpreted by the PCRE engine and not by PHP:

'/^([^\x00-\x1F]+?){0,1}/'

It seems that this is an already known bug (see Problems with strings containing \x00).




回答3:


I am not sure about php, but maybe the problem is that you need to escape your backslashes? try "/^([^\\x00-\\x1F]+?){0,1}/"



来源:https://stackoverflow.com/questions/3665962/regular-expression-error-no-ending-delimiter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!