我需要一个与英国邮政编码匹配的正则表达式,包括部分和完整的邮政编码。
我已经尝试过先前线程中的各种堆栈溢出建议
以前的尝试
var partialPostCode = /^(([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})?))$/;
预期
partialPostCode.test('jt14 8eb') => true (previous regex true)
partialPostCode.test('jt14 8e')=> true (previous regex false)
partialPostCode.test('jt14') => true (previous regex true)