Start a new topic

RegEx to put spaces in UK postcodes

Any thoughts on a RegEx dictionary that puts a space in the right place in UK postcodes? They should be formatted like this CH63 8PH or like (just making one up) W1 8TY. So three or four characters, and space, and then three characters. Just in case they come in all squished together like CH638PH.


Here is more info. Anyway, it is always 3 characters at the end.

The format is as follows, where A signifies a letter and 9 a digit:
Format Coverage Example
AA9A 9AA WC postcode area; EC1–EC4, NW1W, SE1P, SW1 EC1A 1BB
A9A 9AA E1W, N1C, N1P W1A 0AX
A9 9AA B, E, G, L, M, N, S, W M1 1AE
A99 9AA B, E, G, L, M, N, S, W B33 8TH
AA9 9AA All other postcodes CR2 6XH
AA99 9AA All other postcodes DN55 1PT
That would be great! I just spent days formatting all of my international addresses. The appear correctly formatted in NXT so it's really important the are correct. it would also be helpful to have Address Line 3 on the Luminate connector. That is where Luminate forms put the "province/county" information on donation forms.

This worked for me

This is -BLANK-   This is a space " "

      V                       V

The first row replaces space with blank in order to handle correctly formatted zip codes.  Basically it removes all spaces first, then puts a space before the third to last character.


Was there a clip in there somewhere? Link seems to be broken. :(


replace                  match
$1 $2                     ^(.+)(.{3})$


note that the first match value is a space

also both should have regex activated

Thanks Wayne! This is fantastic! Works perfectly for Canadian postal codes standards! 

Login or Signup to post a comment