Forum Moderators: coopster
$pattern = "/[^\d\w\s]/";
$replacement = "*";
$subject = "1 Main str, #5";
echo preg_replace($pattern, $replacement, $subject);
The ^ symbol negate a class. Right after this symbol we put the classes:
\d - digits
\w - words
\s - space
So, it reads as: "replace with * all the symbols from $subject, which are not digits, words and spaces".
$pattern = "/[^\d\w\s]/";
/[^\d\w ]/"
"/^[\d a-z]/i"
Have a read through the Pattern Syntax [uk.php.net] to see exactly what is getting excluded. As \w depends on the locale set, so if your server is in France but you are expecting a-z as 'word' then that isnt all you are going to get, as some of the accented letter will also be in the 'word' character class.