首页 > 解决方案 > PHP preg_grep 多文件

问题描述

如何排除更多像branding.php 这样的文件?例如branding.php、about.php、contact.php。

$pages = preg_grep('/branding\.php/', glob("*.php"), PREG_GREP_INVERT);

谢谢。

标签: arrayspreg-grep

解决方案


在正则表达式中使用替代:

$pages = preg_grep('/\b(?:branding|about|contact)\.php/', glob("*.php"), PREG_GREP_INVERT);

在哪里

  • \b   :单词边界以避免匹配abrandingabc123about...
  • (?:branding|about|contact):匹配brandingOR aboutOR的非捕获组contact(您可以添加更多文件)

推荐阅读