Silver Light
Silver Light

Reputation: 45932

Regular expression error: no ending delimiter

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.

Upvotes: 1

Views: 3004

Answers (3)

Gumbo
Gumbo

Reputation: 655489

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

Upvotes: 4

Artefacto
Artefacto

Reputation: 97835

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.

Upvotes: 3

einarmagnus
einarmagnus

Reputation: 3590

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

Upvotes: 1

Related Questions