Forum Discussion

Matt's avatar
Matt
New Contributor
6 years ago

Removing leading characters

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

  • 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#StringFunctionsandProperties-replace


    1. 0 ↩︎

    • Matt's avatar
      Matt
      New Contributor

      Thank you cjhoward18!

      This did the job perfectly.

    • the_pan_zone's avatar
      the_pan_zone
      New Contributor

      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?

      • bojanvelevski's avatar
        bojanvelevski
        Valued Contributor

        Hi @the_pan_zone,

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

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