使用preg_match_all在字符串中显示无效字符

时间:2014-08-16 18:53:59

标签: php regex preg-match preg-match-all

正则表达式的正确模式是:

$pattern = '/^[A-Z0-9,: \']+$/';

含义,文本中只允许使用字符A-Z,数字0-9,逗号,冒号和撇号。

如何仅使用preg_match_all来显示哪些字符无效?

preg_match($pattern,$text,$match); // $match would return the valid match

匹配无效字符的正确模式是什么(不是A-Z,不是0-9,不是逗号或冒号或撇号)?

1 个答案:

答案 0 :(得分:2)

您的模式很容易否定。您可以在preg_match_alldemo):

中使用此功能
/[^A-Z0-9,: \']/