Found the following nice regex to match all printable ASCII characters:
[ -~]
My code looks like this:
$string = "My ASCII string is (not) very funny.";
filter_var($string, FILTER_VALIDATE_REGEXP,
array("options"=>array("regexp"=>"/^[ -~]*$/")));
Thats almost what I need however I want to exclude the colon. I have tried [ -~\:] and [ -~^:] which does not work. What is the correct regex and how to exclude single characters correctly?
Looks like that you're looking for a regex like this:
(?=[ -~])[^:]
You can exclude also the semicolon by adding it to the "exclude list" :
(?=[ -~])[^:;]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With