2 Replies Latest reply on Feb 26, 2010 2:48 AM by Peter Kahrel

    How Do I create a GREP Expression to Delete Leading Zero's

    Stancaines

      Hello, I Have a text document that I need to Change The files i have look  like this.

       

       

       

       

      220080007      01      01000000320COMPANY           NAME NAME                    004095521

       

       

       

      There are over a hundred thousand records similar to this. The Problem is I Need GREP Expression to change the last field (004095521)

      to ($4095521).

      Also after that That I would like to ad Decimal points to the numbers Ex. ($40955.21)

      Also note that in some of the records the last field also has 1, and sometimes 3 or 4 zeroes example (000409155) (014095523) (000095523)

      However the characters is always 9.

       

       

      Am using indesign CS3

       

      Please Help

      Thank you.

        • 1. Re: How Do I create a GREP Expression to Delete Leading Zero's
          Shonkyin Level 3

          However the characters is always 9.

           

          As you say characters is always 9 and it stand in last of your paragraph?

           

          If your digit stand last in your paragraph then try below code:

           

          var myDoc =  app.activeDocument;

          app.changeGrepPreferences = NothingEnum.nothing;

          app.findGrepPreferences = NothingEnum.nothing;

          app.findGrepPreferences.findWhat = '\\d+$';

          app.findGrepPreferences.appliedParagraphStyle = 'insert your paragraph style';//insert your paragraph style applied on digits

          app.findGrepPreferences.appliedCharacterStyle = 'insert your character style';//insert your character style applied on digits or remove this line if no character style applied

          var myFound = myDoc.findGrep();

          app.changeGrepPreferences = NothingEnum.nothing;

          app.findGrepPreferences = NothingEnum.nothing;

           

          for (a=myFound.length-1; a>=0; a--)

          {

          myFound[a].contents = "($" + myFound[a].contents + ")."

          }

           

           

           

          Shonky

          • 2. Re: How Do I create a GREP Expression to Delete Leading Zero's
            Peter Kahrel Adobe Community Professional & MVP

            You don't need a script for this. You can remove the leading zeroes and add the decimal points in one expression. In the Find/Change dialog, GREP tab, do this:

             

            Find what: (?<=\s)0*(\d+)(\d\d)$

            Change to: $$1.$2

             

            i.e "find a space followed by any zeroes, followed by any digits (capture these) followed by two digits (capture these too) at the end of a paragraph ($). Replace these with a dollar sign followed by the first capture, a decimal point, and the second capture.

             

            Peter