I have a snippet of PHP that replaces all characters from the left not being Unicode letters. It works fine, with one exception, and I can't figure out why. Can anyone help?
<?php
$B=$A;
do{
$A=$B;
$B=preg_replace('/^[^\pL\s]/','',$B);
}
while($B!=$A);
echo $B;
?>
If I feed it with a string like "\\*^&\\\@@\816.80831téstmé"
it nicely spits out "téstmé"
.$A="*^&\\\@@\816.80831[+"
gives an empty string, also correct.
But, when I enter "\\*^&\\\@@\816.80831"
, I end up with "831"
, when in fact it should be an empty string.
"^&\\\@@\8016.8048.31"
gives "48.31"
"^&\\\@@\8016.8148.31"
gives an empty string correctly"^&\\\@@\8016.8148067"
gives "16.8148067"
"^&\\\@@\8116.8148167"
the again is empty
It seems to have somethinh to do with the zero and the dot, but I can't find a pattern nor a solution. I tried adding strval, but still the same result. Maybe someone has an answer? Thnx.
I honestly can not find out why this is going wrong. It has to be some sort of bug. However there is a simple solution.
<?php
$B=preg_replace('/^[^\pL\s]*/','',$A);
This way it has the same functionality, except it works and has a lot less overhead.
Update: i did some testing in Java, regex coach and regexpal.com and they all do it correctly. So this has to be a bug in preg_replace.