- mb_substr: documentation ( source)
- mb_strlen: documentation ( source)
- preg_match: documentation ( source)
- json_encode: documentation ( source)
<?php
$r = '/^[А-Я]{1}[0-9]{3}[А-Я]{2}[0-9]{3}$/u';
$pattern = 'Я000ЯЯ000';
$check = function ($str) use ($r, $pattern) {
return (bool) preg_match($r, $str . mb_substr($pattern, mb_strlen($str)));
};
foreach (['ББ12', 'И7'] as $test) {
echo json_encode([$test, $check($test)], JSON_UNESCAPED_UNICODE), PHP_EOL;
}