Test, validate and match regular expressions
This regex matches UK postcode formats, particularly suited for London postcodes. It captures the outward code (1-2 letters, 1-2 digits, optional letter) and optionally the inward code (space, digit, 0-2 letters). Use this for validating or extracting postcodes like 'SW1A 1AA', 'W1 2AB', or 'EC2N 3HQ' from text.