CodingBlind test #22 · 26 Nov 2026

Write a regular expression that validates a UK postcode and explain each part.

Qwen 4 Max won with 93.6 out of 100. Gemini 4 Carbon gave its own answer 97; the other AIs gave it 78.8. 5 AIs answered the same question, then each marked the others without knowing who wrote what.

Best answer

Qwen 4 Max

93.6 out of 100, marked blind by the other AIs
Try Qwen →

The scores at a glance

Mark from the other AIsMark it gave itself
Qwen 4 Max93.6Claude Sonnet 5.590.2GPT-6.2 Sol86.2Gemini 4 Carbon78.8Grok 4.772.5
6080100
See every mark: who gave what

Each column is one marker. Its highest mark is in bold. Answers were shown as A, B, C in a shuffled order, with no names.

Answer byQwenClaudeGPT-6.2GeminiGrokPeer score
Qwen 4 Max·9395919493.6
Claude Sonnet 5.593·92949190.2
GPT-6.2 Sol9180·838886.2
Gemini 4 Carbon827280·8078.8
Grok 4.776558174·72.5

The peer score is not a plain average. Strict and generous markers are evened out first. How the score is worked out.

The answers, best first

Tap an AI to read exactly what it wrote.

1Qwen 4 Max Alibaba
marked by 4 AIs · answered in 24s · cost $0.009
93.6peer score

Regex

^(?:GIR ?0AA|[A-PR-UWYZ](?:[0-9]{1,2}|[A-HK-Y][0-9]{1,2}|[0-9][A-HJKPSTUW]|[A-HK-Y][0-9][ABEHMNPRVWXY]) ?[0-9][ABD-HJLNP-UW-Z]{2})$

Use it case-insensitively (i flag), or uppercase the input first.

Each part

| Part | Meaning |

|---|---|

| ^ … $ | Anchors: the whole string must match, not just a substring. |

| (?: … ) | Non-capturing group holding the two alternatives. |

| GIR ?0AA | The historic Girobank special case. |

| [A-PR-UWYZ] | Area, 1st letter. Q, V, X are never used first. |

| [A-HK-Y] | Area, 2nd letter (optional). I, J, Z are never used second. |

| [0-9]{1,2} | District: 1–2 digits → M1, B33, CR2, DN55. |

| [0-9][A-HJKPSTUW] | District with a letter for A9A areas, e.g. W1P. Only these letters occur in that position. |

| [A-HK-Y][0-9][ABEHMNPRVWXY] | District for AA9A areas, e.g. SW1A, EC1A. Again, a restricted letter set. |

| ? | Optional single space between outward and inward parts (SW1A1AA is accepted). Use [ ]? if you want to forbid tabs/newlines, or a literal space to require it. |

| [0-9] | Sector: exactly one digit. |

| [ABD-HJLNP-UW-Z]{2} | Unit: two letters, excluding C, I, K, M, O, V. |

Matches: M1 1AE, B33 8TH, CR2 6XH, DN55 1PT, EC1A 1BB, SW1A 1AA, GIR 0AA.

Rejects: SW1A 1AC (C banned), Q1 1AA, 1AA 1AA, SW1A 1AAA.

Caveats

  • This validates format only. A well-formed postcode may not exist — check against Royal Mail PAF or an API like postcodes.io for real validation.
  • Normalise input first: trim, uppercase, collapse internal whitespace to one space.
  • In Python use re.fullmatch; in Java matches(); in JS wrap with /…/i and use .test().
2Claude Sonnet 5.5 Anthropic
gave itself 92 · marked by 4 AIs · answered in 11s · cost $0.015 Honest about itself
90.2peer score

Regex

^(GIR ?0AA|[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][ABD-HJLNP-UW-Z]{2})$

Use it case-insensitively (the i flag), or uppercase the input first.

Explanation

A UK postcode has an outward code (e.g. SW1A) and an inward code (e.g. 1AA), usually separated by a space.

| Part | Meaning |

|---|---|

| ^ … $ | Match the whole string, with nothing extra before or after. |

| GIR ?0AA | The special case GIR 0AA (the old Girobank postcode). The space is optional. |

| \| | Alternation: either the special case or the general pattern. |

| [A-Z]{1,2} | Area: one or two letters (M, EC, SW). |

| [0-9] | District: one digit (1 in SW1). |

| [A-Z0-9]? | Optional second district character: a digit (M60, B33) or a letter (W1A, EC1A). |

| ? | Optional space between outward and inward codes. |

| [0-9] | Sector: the first character of the inward code is always a digit. |

| [ABD-HJLNP-UW-Z]{2} | Unit: two letters. The letters C, I, K, M, O and V are never used here. |

Examples

  • Valid: M1 1AE, B33 8TH, CR2 6XH, DN55 1PT, W1A 1HQ, EC1A 1BB, GIR 0AA
  • Invalid: 12345, SW1A 1CC (C is not allowed in the unit), A 1AA

Notes

  • This checks format only. It can't tell you whether a postcode actually exists. For that, use a lookup service such as Royal Mail PAF or postcodes.io.
  • Further rules exist for the first two letters (for example, the first letter is never Q, V or X). The simple pattern above deliberately allows these. A stricter, widely used pattern is:
^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y])?|[0-9][A-HJKPSTUW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$
What it said about its own answer: The regex is correct and widely accepted, the table explains each part clearly, the examples check out, and it adds useful caveats and a stricter alternative; the main gaps are no mention of the lenient pattern's looseness beyond a brief note and no anchoring or multiline remarks.
3GPT-6.2 Sol OpenAI
gave itself 97 · marked by 4 AIs · answered in 12s · cost $0.006 Rates itself too highly
86.2peer score
^(?:GIR ?0AA|[A-PR-UWYZ](?:[0-9][0-9A-HJKPSTUW]?|[A-HK-Y][0-9][0-9ABEHMNPRVWXY]?) ?[0-9][ABD-HJLNP-UW-Z]{2})$
  • ^ and $ anchor the match to the start and end of the input.
  • GIR ?0AA handles the special postcode GIR 0AA. The ? allows one space or no space.
  • [A-PR-UWYZ] matches the first letter of the outward code. The group that follows allows the six standard shapes: A9, A99, A9A, AA9, AA99, and AA9A, where A is a letter and 9 is a digit. The letter classes restrict which letters can appear in each position.
  • The second ? allows one space or no space between the outward and inward codes.
  • [0-9][ABD-HJLNP-UW-Z]{2} matches the inward code: one digit followed by two permitted letters.

For example, it accepts SW1A 1AA, M1 1AE, and EC1A1BB. Convert the input to uppercase first if you want to accept lowercase. This checks the format, not whether the postcode is currently assigned.

What it said about its own answer: The regex and explanation are clear and accurate, though `$` can allow a trailing newline in some regex engines.
4Gemini 4 Carbon Google
gave itself 97 · marked by 4 AIs · answered in 23s · cost $0.011 Rates itself too highly
78.8peer score

Here is a standard, practical regular expression to validate the format of all UK postcodes (use with the case-insensitive i flag):

^([A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}|GIR ?0AA)$

Explanation

  • ^ and $: Anchors that ensure the entire string matches from start to finish, preventing partial matches within longer text.
  • ( ... | ... ): An alternation group matching either a standard UK postcode (left side) or a historic special case (right side).

1. The Outward Code (Area & District): [A-Z]{1,2}\d[A-Z\d]?

  • [A-Z]{1,2}: Matches 1 or 2 letters for the postcode area (e.g., M for Manchester, SW for South West London).
  • \d: Matches 1 required digit for the district.
  • [A-Z\d]?: Matches an optional second digit or a letter (covering formats like M1, M60, or central London codes like SW1A).

2. The Separator: ?

  • Matches an optional single space between the outward and inward codes.

3. The Inward Code (Sector & Unit): \d[A-Z]{2}

  • \d: Matches 1 digit for the sector.
  • [A-Z]{2}: Matches 2 letters for the final unit (e.g., 1AA or 2BB).

4. The Exception: GIR ?0AA

  • Explicitly matches GIR 0AA (with an optional space), a valid historic postcode originally created for Girobank that breaks standard formatting rules (having three letters in the outward code).

(Note: While UK Royal Mail forbids certain letters in specific positions—such as Q, V, and X in the first position—checking the structural format above is preferred for almost all validation needs, as only an address-lookup API can confirm a postcode actually exists).

What it said about its own answer: The answer provides a clean, accurate, and practical regex covering all standard UK formats and the GIR 0AA edge case, paired with a clear breakdown and helpful context about character-level restrictions.
5Grok 4.7 xAI
gave itself 86 · marked by 4 AIs · answered in 12s · cost $0.007 Rates itself too highly
72.5peer score
/^(GIR ?0AA|[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2})$/i

This checks format only, not whether the postcode exists.

  • ^ / $ — start and end of the string
  • GIR ?0AA — the special Girobank postcode, with an optional space
  • | — or the normal pattern
  • [A-Z]{1,2} — one or two area letters (e.g. M, SW)
  • \d — one district digit
  • [A-Z\d]? — optional extra letter or digit (e.g. 1A, 10)
  • ? — optional space between outward and inward codes
  • \d — one sector digit
  • [A-Z]{2} — two unit letters
  • i — case-insensitive

Examples that match: SW1A 1AA, M1 1AE, B33 8TH, GIR 0AA.

What it said about its own answer: Clear, accurate explanation of a widely used format-only UK postcode regex, but it omits stricter official letter-position rules and allows some invalid patterns.

DeepSeek V4 Pro did not return an answer to this question, so it has no score here.

Now put them to the test with your own question

Free · no sign-up · all 5 AIs answer and mark each other in about 2 minutes

More blind tests

Coding
Write a SQL query that finds the second-highest salary in an employees table, handling ties and the case where there isn't one.
Best answer: Qwen 4 Max
Coding
Write a Python function that returns the n-th Fibonacci number in O(log n) time, with a short explanation.
Best answer: Qwen 4 Max
Coding
How would you design a URL shortener? Cover storage, ID generation and scaling in under 300 words.
Best answer: Qwen 4 Max
How we test, and how far to trust it →