# Calculating Postcode Sector from Postcode value

**URL:** https://forum.cloverdx.com/t/calculating-postcode-sector-from-postcode-value/1276
**Category:** CloverDX Platform
**Created:** [September 24, 2013, 12:00am UTC](https://forum.cloverdx.com/t/calculating-postcode-sector-from-postcode-value/1276 "2013-09-24T00:00:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nhanson](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@nhanson](https://forum.cloverdx.com/u/nhanson)
#### Post date: [September 24, 2013, 12:00am UTC](https://forum.cloverdx.com/t/calculating-postcode-sector-from-postcode-value/1276/1 "2013-09-24T00:00:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![novakj](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@novakj](https://forum.cloverdx.com/u/novakj)
#### Post date: [September 24, 2013, 2:14pm UTC](https://forum.cloverdx.com/t/calculating-postcode-sector-from-postcode-value/1276/2 "2013-09-24T14:14:42Z")

</div>

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.
