Calculating Postcode Sector from Postcode value

Hi

I’d like to create a new field in my reformat component for a Postcode Sector value which gives everything plus the 1st character past the space on a postcode.

So a couple of examples are
Postcode is AA1 2BB and I would like to have PC Sector returned as AA1 2
Postcode is A1 2BB and I would like to have PC Sector returned as A1 2
Postcode is AC1V 2 and I would like to have PC Sector returned as AC1V 2

Could someone advise on what the best function would be to do this? I’ve tried to do a left, length but this does not work for the 2nd and 3rd examples.

Thanks
Nikki

Hi Nikki,

You can use this transformation expression in your Reformat component:

function integer transform() {
$out.0.postcode = replace($in.0.postcode, “([^ ]* .).*”, “$1”);
return ALL;
}

There is a regular expression which matches everything to the first occurrence of space, one space and one character. I hope it will help you.