Skip to main content

I’m setting up a logic sequence that takes any UK postcode and removes the final 3 characters and returns the remaining characters.

e.g.

B48OP becomes B4

B755UG becomes B75

and WV125ET becomes WV12

The postcode string could be 5, 6 or 7 characters long - in each case I want to remove the final 3 characters and return the remaining characters as above. I’ve already created steps to remove spaces and make upper case - it’s just this final bit I can’t figure out.

Any ideas?

Hi @Hyde 

Good question.

Check out this related topic:

https://community.zapier.com/featured-articles-65/slice-text-with-javascript-code-14510


Hi Troy, thanks for this!

Ok, so I’ve followed that and used the following code to slice off the final 3 characters from the testing value “PR26QY”

 

let Text = inputData.Text;

let Text1 = Text.slice(-3);

output = u{Text1}];

 

But then it’s the final 3 characters “6QY” that are returned in the output and not the initial string which I need.

Can I use some code to remove the above output from the initial string to leave the remaining characters? Something like the following:

Output = :{Text} minus {Text1}]

?


@Hyde 

Try .slice(0,-3);


That’s worked perfectly, thanks again for the help!