My question is, why does the position of the '_' (underscore) character cause this problem?
I have inherited a script that is using php's preg_replace in a function. The regex used is returning a 0 on any number it is used on.
function foo($number){
$number = preg_replace('/[a-z$,-_]/i','',$number);
// more code...
}
I did a bunch of debugging and found the problem was with the preg_replace(). A co-worker mentioned that the order of the characters in the regex maybe causing the bug. So, I played with this and found it to be true. The position of the '_' (underscore) character is the sinister culprit. I changed this to:
'/[a-z$_,-]/i'
... and everything works fine.
So, the question, again, is why does the position of the '_' (underscore) character cause this problem? I've Googled on this but have not found it and I thought the minds in this forum may have the answer.
Thanks for any enlightenment! -jc