views:

41

answers:

2

Afternoone guys and girls.

having a bit of trouble with replacing things that are NOT 0-9A-Za-z[:space] because I cannot find a NOT metachar for preg_replace. Does anytone know if one exists and if not what is the best way to strip anything that is NOT alpha numeric or a space?

Thanks in advance

Alex

+2  A: 

Use negated character classes:

/[^A-Za-z0-9 ]/

You could also use the \w escape sequence, which is equivalent to [a-zA-Z0-9_] (note the underscore). So your regex would look like

/[^\w ]/

Reference:

http://www.regular-expressions.info/charclass.html

NullUserException
Thanks mate, you are a life saver.Kind regardsAlex
Alex
@Alex see updated answer
NullUserException
@Alex: You should also accept one of the answers given you; that is how Stack Overflow works. `:-)`
kiamlaluno
A: 

More useful:

/[^A-Za-z0-9 ]+$/
Alexander.Plutov