PHP regex匹配数字范围,即17-21

时间:2018-11-20 13:54:49

标签: php regex

我有以下代码可以正常工作,它试图从英国邮政编码中排除英国的高地和岛屿,但是下面两行引发了错误,下面是为什么?

$strPostCode = 'AB393HX';

if(!preg_match('/^(ZE|IV|TR|GY|JE)[0-9]/',$strPostCode)

   && !preg_match('/^(AB)[31-38]{2}/',$strPostCode)

   && !preg_match('/^(AB)[41-45]{2}/',$strPostCode)
   && !preg_match('/^(AB)[55-56]{2}/',$strPostCode)

   && !preg_match('/^(PA)[20-78]{2}/',$strPostCode)

   && !preg_match('/^(PH)[15-99]{2}/',$strPostCode)

   && !preg_match('/^(FK)[17-21]{2}/',$strPostCode) // Compilation failed: range out of order in character class at offset 9 

   && !preg_match('/^(KA)[27-28]{2}/',$strPostCode) // Compilation failed: range out of order in character class at offset 9 

   && !preg_match('/^(HS)[1-9]{1}/',$strPostCode)

   && !preg_match('/^(KW)[0-9]{1}/',$strPostCode)

   && !preg_match('/^(KW)[10-17]{2}/',$strPostCode)
   ){
    echo $strPostCode . ' is good';
   }
    else{
      echo $strPostCode . ' is bad';
   }

0 个答案:

没有答案