<?php
$arr_postcode_regexes = [
'offshore' => [
['A', 'B', '3', '[0-8]'], // AB30-38
['A', 'B', '4', '[1-9]'], // AB41-49
['A', 'B', '5', '[0-6]'], // AB50-56
['F', 'K', '1', '[789]'], // FK17-19
['F', 'K', '2', '[01]'], // FK20-21
['G', '8', '3'], // G83
['G', 'Y', '9'], // GY9
['H', 'S', '[1-9]'], // HS1-9
['I', 'M', '[0-9]', '[0-9A-Z]?'], // IM
['I', 'M', '[0-9]', '[0-9A-Z]?'], // IV
['K', 'A', '2', '[89]'], // KA27-28
['K', 'W', '[0-9]', '[0-9]?'], // KW0-99
['P', 'A', '[2-9]', '[0-9]'], // PA20-99
['P', 'H', '1', '[5-9]'], // PH15-19
['P', 'H', '[2-9]', '[0-9]'], // PH20-99
['T', 'R', '2', '[1-5]'], // TR21-25
['Z', 'E', '[0-9]', '[0-9A-Z]?'], // ZE
],
'ni' => [
['B', 'T', '[0-9]', '[0-9A-Z]?'], // ZE
]
];
// Turn the readable-ish map above into actual regexes
// It's important that all regexes match only full, valid postcodes, as prefix matching can be ambiguous.
foreach ($arr_postcode_regexes as $str_id => $arr_parts) {
$arr_temp = [];
foreach ($arr_parts as $arr_part) {
$arr_temp[] = implode('\s*', $arr_part) . '\s*[0-9]\s*[A-Z]\s*[A-Z]';
}
$arr_postcode_regexes[$str_id] = '^\s*(' . implode('|', $arr_temp) . ')\s*$';
}
var_dump($arr_postcode_regexes);
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(2) {
["offshore"]=>
string(738) "^\s*(A\s*B\s*3\s*[0-8]\s*[0-9]\s*[A-Z]\s*[A-Z]|A\s*B\s*4\s*[1-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|A\s*B\s*5\s*[0-6]\s*[0-9]\s*[A-Z]\s*[A-Z]|F\s*K\s*1\s*[789]\s*[0-9]\s*[A-Z]\s*[A-Z]|F\s*K\s*2\s*[01]\s*[0-9]\s*[A-Z]\s*[A-Z]|G\s*8\s*3\s*[0-9]\s*[A-Z]\s*[A-Z]|G\s*Y\s*9\s*[0-9]\s*[A-Z]\s*[A-Z]|H\s*S\s*[1-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|I\s*M\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z]|I\s*M\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z]|K\s*A\s*2\s*[89]\s*[0-9]\s*[A-Z]\s*[A-Z]|K\s*W\s*[0-9]\s*[0-9]?\s*[0-9]\s*[A-Z]\s*[A-Z]|P\s*A\s*[2-9]\s*[0-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|P\s*H\s*1\s*[5-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|P\s*H\s*[2-9]\s*[0-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|T\s*R\s*2\s*[1-5]\s*[0-9]\s*[A-Z]\s*[A-Z]|Z\s*E\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z])\s*$"
["ni"]=>
string(59) "^\s*(B\s*T\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z])\s*$"
}
- Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[' in /in/urL1v on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected '[' in /in/urL1v on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/urL1v on line 3
Process exited with code 255.
preferences:
320.7 ms | 401 KiB | 459 Q