I need to strip unwanted characters from a string. I want to use preg replace, but I am useless at regular expressions.
My string should only allow a-z A-Z 0-9 and spaces. No other characters.
So for example:
some string's-are#bad
would become:
some stringsarebad
Many thanks
You can use this:
To explain this:
/opening delimiter — start the regex[^start negative character group — match anything except what’s in this selectiona-z0-9match alphabetic and numeric characters and spaces]close character group/closing delimitericase insensitive search — matchA-Zas well