So I have got this far on my own but It looks like I have found the limit of my PHP knowledge (which isn\'t very much at all!). This script is for filtering filenames (game roms
Replace the fourth line in the code you supplied with
$manualRemovePattern = "/(?:" . implode("|", array_map(function($i) {
return preg_quote(trim($i), "/");
}, explode(PHP_EOL, $file))) . ')/';
The main idea is:
explode(PHP_EOL, $file)
array_map
)\
before any special regex metacharacter and a regex delimiter chosen by you (in this case, /
), and this is done with preg_quote(trim($i), "/")
trim
from the array items - just in case.To match them as whole words, use word boundaries:
$manualRemovePattern = '/\b(?:' . implode('|', array_map(function($i) {
return preg_quote(trim($i), '/');
}, explode(PHP_EOL, $file))) . ')\b/';
To match them as whole strings, use ^
/$
anchors:
$manualRemovePattern = '/^(?:' . implode('|', array_map(function($i) {
return preg_quote(trim($i), '/');
}, explode(PHP_EOL, $file))) . ')$/';