I have a strange behaivor of the preg_match in PHP.
For checking a sql query, is there an unescaped assign of a value, I've wrote the following regexp, and piece of code. (See below).
The pattern:
=[\s]*'[^'|^\\']*'[^']*'
The expected result
'val\'ue' //Result should be 0
'value' //Result should be 0
'val'ue' //Result should be 1!!!
So, I've checked it in Regex Coach (native regex tester on windows), and on an online regex tester, and I've get back the expected result.
Ok, so it's seems, my pattern is works. Now I am do it in PHP:
$values = array(
"='val\'ue'",
"='value'",
"='val'ue'"
);
$pattern = "=[\s]*'[^'|^\\']*'[^']*'";
echo "Pattern is: " . $pattern . "<br>";
foreach ($values as $value) {
echo "Value is: " . $value . "<br>";
var_dump(preg_match("/" . $pattern . "/i", $value, $matches));
}
And guess what:
Pattern is: =[\s]*'[^'|^\']*'[^']*'
Value is: ='val\'ue'
int 1 //<------- THIS SHOULD BE ZERO!
Value is: ='value'
int 0
Value is: ='val'ue'
int 1
Maybe I am so tired, and make an obvious mistake, plese help mi out, what do I wrong.
/, to match a single backslash, you need to put////four or three backslashes. - Avinash Raj~and he will be happy :D - Rizier123~or@, the result is the same. - vaso123'? - vaso123