@ 2023-11-23T00:53:04Z <?php
$string = 'My nAmE ïs Tom.';
// case-sensitive matching, including partial matching
$array = ['foo', 'nAmE'];
$regex[] = '#' . implode('|', array_map('preg_quote', $array)) . '#';
// case-insensitive matching, including partial matching
$array = ['foo', 'om'];
$regex[] = '#' . implode('|', array_map('preg_quote', $array)) . '#i';
// case-insensitive matching, full word matching only
$array = ['foo', 'tom'];
$regex[] = '#\b(?:' . implode('|', array_map('preg_quote', $array)) . ')\b#i';
// case-insensitive matching, full word matching only, multibyte aware
$array = ['foo', 'ïs'];
$regex[] = '#\b(?:' . implode('|', array_map('preg_quote', $array)) . ')\b#iu';
foreach ($regex as $r) {
if (preg_match($r, $string, $m)) {
echo "found '$m[0]' using $r on $string\n";
} else {
echo "no match using $r on $string\n";
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.1 - 8.0.30 , 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 found 'nAmE' using #foo|nAmE# on My nAmE ïs Tom.
found 'om' using #foo|om#i on My nAmE ïs Tom.
found 'Tom' using #\b(?:foo|tom)\b#i on My nAmE ïs Tom.
found 'ïs' using #\b(?:foo|ïs)\b#iu on My nAmE ïs Tom.
preferences:dark mode live preview ace vim emacs key bindings
73.38 ms | 407 KiB | 5 Q