tags:

views:

79

answers:

3

Hello!

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  A: 

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

ormuriauga
it could be that \x00 gets interpreted as end of string before it gets handed over to the regex engine
ormuriauga
+5  A: 

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).

Gumbo
Thank you, this works. I with I could accept 2 answers.
Silver Light
+3  A: 

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.

Artefacto
Thank you for example. I used your variant.
Silver Light