【问题标题】:Displaying the invalid characters in a string using preg_match_all使用 preg_match_all 显示字符串中的无效字符
【发布时间】:2014-08-16 18:53:58
【问题描述】:

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

$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、不是逗号、冒号或撇号)的正确模式是什么?

【问题讨论】:

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


    【解决方案1】:

    你的模式很容易被否定。您可以在 preg_match_all (demo) 中使用它:

    /[^A-Z0-9,: \']/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 2021-07-22
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-02
      相关资源
      最近更新 更多