I want to extract the outcode of a UK postcode. All the background is here: UK Postcode Regex (Comprehensive)
But it's not validation, so this should do:
- first 2 characters for a postcode of length 5
- first 3 characters for a postcode of length 6
- first 4 characters for a postcode of length 7
All postcodes are converted to upper case and no spaces.
I cannot figure out how to specify dynamic ranges. Or whatever works.
Pseudo-code ^[A-Z0-9]{length(postcode) - 3}
Added: I'm using R.