cancel
Showing results for 
Search instead for 
Did you mean: 

Removing leading characters

Matt
New Contributor

I’m receiving data with 18 characters, which includes 7 leading 0s. Would I use the Mapper to TRIM off the leading 0s? If so how would I go about this?

Thank you

4 REPLIES 4

cjhoward18
Employee
Employee

Hi Matt,

you can use the expression language, specifically the replace() method to achieve this.

expression: “0000000helloworld.”.replace(/([1]+)/, “”)

result: helloworld.

This uses a regex to trim ALL leading zeros from your given string.

If you would like to specifically always only remove the 7 leading zeros you can use this.

expression: “0000000helloworld.”.replace(“0000000”, “”)

result: helloworld.

which specifically removes the first 7 zeros found in the string, in this case the 7 leading zeros your looking to remove.

here is documentation in case you want to refer to it:
https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1439357/String+Functions+and+Properties#St...


  1. 0 ↩︎

Thank you cjhoward18!

This did the job perfectly.

Hi @cjhoward18 ,
How can I extract number only from a string
My input is FR4535345, fgfh345
My out put should be 4535345,345

Is there any find index of a first digit in a string in snaplogic?

Hi @the_pan_zone,

You can use the .match() function with the following regex included:

$string.match(/[0-9]+/g)