3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $pattern = "#^(([gG][iI][rR] {0,}0[aA]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y])))( {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2})?))$#"; $check = array( "LE1 1AA", "LE1", "SN5" ); $match = null; foreach($check as $c){ if(preg_match($pattern, $c, $match)){ echo "$c matches -> {$match[0]}\n"; } }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
LE1 1AA matches -> LE1 1AA LE1 matches -> LE1 SN5 matches -> SN5