标签: php regex preg-match preg-match-all
正则表达式的正确模式是:
$pattern = '/^[A-Z0-9,: \']+$/';
含义,文本中只允许使用字符A-Z,数字0-9,逗号,冒号和撇号。
如何仅使用preg_match_all来显示哪些字符无效?
preg_match_all
preg_match($pattern,$text,$match); // $match would return the valid match
匹配无效字符的正确模式是什么(不是A-Z,不是0-9,不是逗号或冒号或撇号)?
答案 0 :(得分:2)
您的模式很容易否定。您可以在preg_match_all(demo):
/[^A-Z0-9,: \']/