arrays - PHP preg_grep 多文件
问题描述
如何排除更多像branding.php 这样的文件?例如branding.php、about.php、contact.php。
$pages = preg_grep('/branding\.php/', glob("*.php"), PREG_GREP_INVERT);
谢谢。
解决方案
在正则表达式中使用替代:
$pages = preg_grep('/\b(?:branding|about|contact)\.php/', glob("*.php"), PREG_GREP_INVERT);
在哪里
\b
:单词边界以避免匹配abranding
或abc123about
...(?:branding|about|contact)
:匹配branding
ORabout
OR的非捕获组contact
(您可以添加更多文件)
推荐阅读
- android - 如何为公共片段创建不同的视图模型?
- c - 无法接收聊天程序的消息
- mysql - 如何使以下查询在具有许多条件的查找中更有效
- java - 有没有办法在 android studio 中修复我的屏幕网格?
- asp.net - 在 selectedindexchanged 上的 gridview 中获取单选按钮列表的选定值
- function - 有没有更好的方法在 PROC SQL 中使用嵌套函数?
- python - 扭曲的 deferToThread addCallback 调用
- mysql - 你如何在另一个文件中使用 MySQL 的源命令
- office-ui-fabric - @fluentui/react-northstar@0.49.0 中的网格响应问题
- php - Laravel SQLSTATE [42S22]:找不到列