2014-01-06 76 views
0

我已經給出了一個英國郵政編碼以下模式:有效的英國郵政編碼正則表達式模式?

([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)

誰能打破這對我?

+1

在Windows regexbu上花費US $ 40迪迪非常值得美元。我在wine下的Linux/Mac上運行它就好了,因爲它一切都很好;) – gwillie

+0

如果你使用PHP,你可能會檢查這個[非正則表達式解決方案](http://stackoverflow.com/問題/ 15960184/UNITED-王國-GB-郵政代碼驗證,而無需正則表達式/ 16303815#16303815)。 – HamZa

回答

2

debuggex.com是調試正則表達式一個非常有用的資源:

Debuggex Demo

+0

這太神奇了。謝謝! – Chud37

3

Here是:

NODE      EXPLANATION 
---------------------------------------------------------------------- 
    (      group and capture to \1: 
---------------------------------------------------------------------- 
    [A-PR-UWYZ0-9]   any character of: 'A' to 'P', 'R' to 
          'U', 'W', 'Y', 'Z', '0' to '9' 
---------------------------------------------------------------------- 
    [A-HK-Y0-9]    any character of: 'A' to 'H', 'K' to 
          'Y', '0' to '9' 
---------------------------------------------------------------------- 
    [AEHMNPRTVXY0-9]?  any character of: 'A', 'E', 'H', 'M', 
          'N', 'P', 'R', 'T', 'V', 'X', 'Y', '0' 
          to '9' (optional (matching the most 
          amount possible)) 
---------------------------------------------------------------------- 
    [ABEHMNPRVWXY0-9]?  any character of: 'A', 'B', 'E', 'H', 
          'M', 'N', 'P', 'R', 'V', 'W', 'X', 'Y', 
          '0' to '9' (optional (matching the most 
          amount possible)) 
---------------------------------------------------------------------- 
    {1,2}     ' ' (between 1 and 2 times (matching the 
          most amount possible)) 
---------------------------------------------------------------------- 
    [0-9]     any character of: '0' to '9' 
---------------------------------------------------------------------- 
    [ABD-HJLN-UW-Z]{2}  any character of: 'A', 'B', 'D' to 'H', 
          'J', 'L', 'N' to 'U', 'W' to 'Z' (2 
          times) 
---------------------------------------------------------------------- 
    |      OR 
---------------------------------------------------------------------- 
    GIR 0AA     'GIR 0AA' 
---------------------------------------------------------------------- 
)      end of \1 
相關問題