Regex regular expressions complain about lookbehind variable length

Here is the code I'm trying to run:

$str = 'a,b,c,d';
return preg_split('/(?<![^\\\\][\\\\]),/', $str);

As you can see, the regex is used here:

/(?<![^\\][\\]),/

This is a simple fixed-length negative lookbehind for which "is preceded by something that is not a backslash, and then something!".

This regex works great at http://www.phpliveregex.com

But when I go and actually try to run the above code, I spat out an error:

Warning:  preg_split() [function.preg-split]: Compilation failed: lookbehind assertion is not fixed length at offset 13

To make matters worse, one programmer tested the code on his 5.4.24 PHP server, and it worked fine.

This makes me think that my problems are related to my server configuration and I have very little control. I was told that my version is PHP, if 5.2. *

- / preg_replace(), ?

+4
3

, PCRE 6.7. :

lookbehind, (?<=[^f]), "lookbehind assertion is not fixed length"

PCRE 6.7 PHP 5.2.0 2006 . , , - , preg-split, . :

$patt = '/(?<!(?<!\\\\)\\\\),/';
// or...
$patt = '/(?<![\x00-\x5b\x5d-\xFF]\x5c),/';

, : , , ? ? ? "", , , , .

preg_match_all , :

$str = 'e ,a\\,b\\\\,c\\\\\\,d\\\\';
preg_match_all('/(?:[^\\\\,]|\\\\(?:.|$))+/', $str, $matches);
var_dump($matches[0]);

.

, , - )

+3

( \x5c, , )

$result = preg_split('/(?<!(?!\x5c).\x5c),/s', $str);

:

, , lookbehind, undefined . :

$result = preg_split('/(?:[^\x5c]|\A)(?:\x5c.)*\K,/s', $str);

$result = preg_split('/(?<!\x5c)(?:\x5c.)*\K,/s', $str);

PHP > 5.2.4

$result = preg_split('/\x5c{2}(*SKIP)(?!)|(?<!\x5c),/s', $str);
+1

, php, PHP 5.1.6 .

enter image description here

, PHP 5.2.16 :

enter image description here

0
source

All Articles