3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ ['word' => 'example', 'mask' => 'lmp'], // true ['word' => 'goodness', 'mask' => 'dns'], // false ['word' => 'slippers', 'mask' => 'eip'], // true ['word' => 'slippers', 'mask' => 'ips'], // false ['word' => 'google', 'mask' => 'go'], // true ['word' => 'food', 'mask' => 'go'], // false ['word' => 'bananas', 'mask' => 'ans'], // true ['word' => 'candle', 'mask' => 'ace'], // false ['word' => 'mississippi', 'mask' => 'i'], // true ['word' => 'executive', 'mask' => 'ecitx'], // false ]; foreach ($tests as ['word' => $word, 'mask' => $mask]) { var_export([ $word, $mask, preg_match_all("/[$mask]+/", $word, $m) && array_filter($m[0], fn($chars) => !ltrim($mask, $chars)), preg_match_all("/[$mask]{" . strlen($mask) . ",}/", $word, $m) && array_filter($m[0], fn($chars) => !ltrim($mask, $chars)), // preg_replace('/[a-z]/', "(?=[$mask]*$0)", $mask), (bool) preg_match('/' . preg_replace('/[a-z]/', "(?=[$mask]*$0)", $mask) . "[$mask]+/", $word) ]); echo "\n---\n"; }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
array ( 0 => 'example', 1 => 'lmp', 2 => true, 3 => true, 4 => true, ) --- array ( 0 => 'goodness', 1 => 'dns', 2 => false, 3 => false, 4 => false, ) --- array ( 0 => 'slippers', 1 => 'eip', 2 => true, 3 => true, 4 => true, ) --- array ( 0 => 'slippers', 1 => 'ips', 2 => false, 3 => false, 4 => false, ) --- array ( 0 => 'google', 1 => 'go', 2 => true, 3 => true, 4 => true, ) --- array ( 0 => 'food', 1 => 'go', 2 => false, 3 => false, 4 => false, ) --- array ( 0 => 'bananas', 1 => 'ans', 2 => true, 3 => true, 4 => true, ) --- array ( 0 => 'candle', 1 => 'ace', 2 => false, 3 => false, 4 => false, ) --- array ( 0 => 'mississippi', 1 => 'i', 2 => true, 3 => true, 4 => true, ) --- array ( 0 => 'executive', 1 => 'ecitx', 2 => false, 3 => false, 4 => false, ) ---
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
158.99 ms | 408 KiB | 5 Q