2 Replies Latest reply on Aug 23, 2013 1:06 AM by Learner Learner

    Re-Numbering numbers

    Learner Learner

      Hi all,


      Can anyone help me I have a document which contains huge numbers say for example it has 1-100 numberes. Here i want to delete some numbers from 1-100 say for example 22, 23, and 23 after deleting these numbers i want to re-numbering the remaining numberes so the final number should be 97.


      Im trying with the below code but unable to found the solution.


      var myDoc = app.activeDocument;

      app.findTextPreferences = null;

      app.findTextPreferences.findWhat = "^9";

      app.findTextPreferences.position = Position.SUPERSCRIPT;

      var myFound = myDoc.findText();

      var change = 0;

      for (var i = 0;i<myFound.length;i++){

          myFound[i].appliedCharacterStyle = myDoc.characterStyles.item("Sup");

          if (myFound[i].appliedCharacterStyle != myDoc.characterStyles.item("Sup")){

           app.changeTextPreferences.changeTo = "" + change;   







      Thanks in advance,




        • 1. Re: Re-Numbering numbers
          Peter Kahrel Adobe Community Professional & MVP

          You need to look for numbers, not digits, so use Grep to find all numbers: \d+

          Find all numbers and replace their contents with the value of the for-loop counter. No need to bother with what the contents really are.

          Then you must work from the end of the found numbers to the beginning because the length of the numbers wioll change, e.g. 10 (two digits) may change to 9 (one digit). Like this


          app.findGrepPreferences = null;
          app.findGrepPreferences.findWhat = '\\d+';
          app.findGrepPreferences.position = Position.SUPERSCRIPT;
          numbers = myDoc.findGrep();
          for (i = numbers.length-1; i > -1; i--){
              numbers[i].contents = String(i+1);
              numbers[i].appliedCharacterStyle = myDoc.characterStyles.item("Sup");



          • 2. Re: Re-Numbering numbers
            Learner Learner Level 1

            Thank you so much Peter.