Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
支持阿鲁巴和巴巴多斯邮政编码的javascript正则表达式_Javascript_Regex - Fatal编程技术网

支持阿鲁巴和巴巴多斯邮政编码的javascript正则表达式

支持阿鲁巴和巴巴多斯邮政编码的javascript正则表达式,javascript,regex,Javascript,Regex,寻找一个正则表达式,允许阿鲁巴和巴巴多斯的邮政编码低于2个 - Aruba - 0000AW (Only 6 characters are allowed in the format 4 digit(only 0) at the beginning and 2 characters (only A and W) at the end ) - Barbados - BB15094 (Only 7 characters are allowed in the format 2

寻找一个正则表达式,允许阿鲁巴和巴巴多斯的邮政编码低于2个

 - Aruba - 0000AW  (Only 6 characters are allowed in the format 4
   digit(only 0) at the beginning and 2 characters (only A and W) at the
   end )

 - Barbados - BB15094 (Only 7 characters are allowed in the format 2
   characters(only B) at the beginning and 4 digits (0 t0 9) at the end)
有人能帮我弄到这个的正则表达式吗

我猜巴巴多斯-
/^[Bb]{2}?[0-9]{5}$/
和阿鲁巴-
/^[0]{4}?[Aa]{1}[Ww]{1}$/

以下是您的正则表达式的“更干净”版本:

巴巴多斯():

:

注意不区分大小写的修饰符
/i
允许将
[aA]
减少为
a
,等等。 您不需要将单个字符包含到字符类中,
[0]
=
0
。使用具有精确出现次数的惰性限制量词,
{4}?
=
{4}
,没有任何意义。默认情况下,
{1}
量词是多余的,因为默认情况下所有原子都匹配一个匹配项(
\d[a-z]
匹配一个数字,后跟一个小写ASCII字母)


请注意,在JS正则表达式中,
\d
等于
[0-9]

30分钟将教会您如何立即编写。@WiktorStribiżew感谢thids链接。对于巴巴多斯,我尝试了/^[Bb][Bb]?[0-9][0-9][0-9][0-9][0-9]$/而且效果不错。但是我不想重复[0-9]5次。你能帮忙吗?你错过了。@WiktorStribiżew明白了我猜巴巴多斯-/^[Bb]{2}?[0-9]{5}$/Aruba-/^[0]{4}?[Aa]{1}[Ww]{1}$/你能验证一下吗?Aruba regex很有趣。1)
/^b{2}\d{5}$/i
2)
/^0{4}aw$/i
/^b{2}\d{5}$/i
/^0{4}aw$/i