preg_replace, exact opposite of a preg_match
- by SoLoGHoST
I need to do a preg_replace for the exact opposite of this preg_match regular expression:
preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string);
So I need to replace all strings that are not valid with an empty string - ''
So it needs to remove the first / and last / if found, and all non-valid characters, that is the only valid characters are A-Z, a-z, 0-9, _, ., and / (if it's not the first or last characters of the string).
How can I accomplish this with the preg_replace?
Thanks :)