i want the regular expression to sanitize my data which should meet the following condition
a) a-z and A-Z allowed
b) 0-9 allowed
c) Special Symbols like Comma (,) dot (.) question Mark (? allowed)
d) Single Space is allowed
i tried and came up with this
preg_replace('%[^a-zA-Z0-9,.?\s]%', '', $string);
i am not so familiar with RegExp, although the above code works, i would like to know
a) if i am using the correct RegExp
syntax?b) if i don’t use
modulus(%)at the
start and end of the syntax it won’t
work, and i have no idea what is the
purpose of modulus here?
a) If it works, it’s correct.
b) “When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character” – from PHP Documentation