简体   繁体   中英

PHP preg_grep multi files

how can I exclude more files like branding.php? For example branding.php, about.php, contact.php.

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

Thx.

Use alternative in the regex:

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

Where

  • \\b : word boundary to avoid matching abranding or abc123about ...
  • (?:branding|about|contact) : non capture group that match branding OR about OR contact (you may add more files)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM