3 Replies Latest reply on May 8, 2014 1:41 AM by [Jongware]

    Grep find & change decimal and thousands

    AsOne Level 1

      Hi All,

       

      I want to find a digits some of types using with grep in single find and change

       

      (1) First type comma(,) for decimal and space for thousands and ten thousands

      1 100 406,50

       

      (2) Second type dot(.) for decimal and comma for thousands and ten thousands

      1,100,406.50

       

      (3) Third type comma(,) for decimal and dot for thousands and ten thousands

      1.100.406,50

       

      for all these i am finding multiple number of times with combination of numbers

       

      my code:

      app.findGrepPreferences.findWhat = "([0-9])\\.([0-9]{2})";

      app.changeGrepPreferences.changeTo = "$1,$2";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

      app.findGrepPreferences.findWhat = "([0-9]{3})\\.([0-9]{3})";

      app.changeGrepPreferences.changeTo = "$1 $2";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

      app.findGrepPreferences.findWhat = "([0-9])\\.([0-9]{3})";

      app.changeGrepPreferences.changeTo = "$1 $2";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

      app.findGrepPreferences.findWhat = "([0-9])\\.([0-9]{3})\\.([0-9]{3})\\.([0-9]{2})";

      app.changeGrepPreferences.changeTo = "$1 $2 $3,$4";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

      app.findGrepPreferences.findWhat = "([0-9]) ([0-9]{3}) ([0-9]{3})\\.([0-9]{2})";

      app.changeGrepPreferences.changeTo = "$1 $2 $3,$4";

      app.changeGrep();

      app.findGrepPreferences = app.changeGrepPreferences = null;

       

       

      but i want to find each type in a single find and change, could any one help

       

      thanks in advance

      steve

        • 1. Re: Grep find & change decimal and thousands
          BEGINNER_X Level 3

          Hi Steve,

           

          I do not understand, what your expect output correctly, but the below code may helpful for you:

           

          app.findGrepPreferences = app.changeGrepPreferences = null;

          app.findGrepPreferences.findWhat = "\\d+\\S+";

           

          Above code find the digit upto the white space comes. It should cover your problem upto 80% only.

           

          Thanks

          Siraj

          • 2. Re: Grep find & change decimal and thousands
            AsOne Level 1

            Hi Siraj,

             

            thanks for your reply

             

            I want to separate the numbers to decimals and thousands, dot(.) for decimals (end of one or two digits) and space( ) for thousands (before the decimal points, thousands separator should space( ).

            EX: 1 123 456.75

             

            between number to number there may be a dot, space or comma, it should be changed to dot(.) for decimals and space( ) for thousands.

             

             

            thanks

            Steve

            • 3. Re: Grep find & change decimal and thousands
              [Jongware] Most Valuable Participant

              AsOne wrote:

              .. but i want to find each type in a single find and change

               

              Why? Doing them one at a time is 1. about as fast, 2. less error-prone, 3. easy maintainable (you can easily add more variations).

               

              You need at least 2 GREPs -- one to change 'any' thousands separator to space, and one to change 'any' decimals separator to period.

               

              For the first, change (?<=\d)[., ](?=\d\d\d) to just a space. For the second, change (?<=\d)[., ](?=\d\d(?!\d)) to a period.