Skip to main content
Regexflux

UK Postcode

intermediate

Matches UK postcodes in standard format.

postcodeukpostalvalidation

Pattern

/[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}/gi

Try It

0 of 8 strings matched

Explanation

Matches UK postcodes: 1-2 letters, digit, optional letter/digit, optional space, digit, 2 letters. Covers all UK postcode formats.

Test Strings

Matching

  • SW1A 1AA
  • EC1A1BB
  • W1A 0AX
  • M1 1AE

Non-matching

  • 12345
  • ABCDE
  • SW1A1
  • 123 456

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}/gi;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns