Increment from value found in file

Increment from value found in file

74
Advanced UserAdvanced User
74

    Mar 15, 2009#1

    Is it possible to do a search in a file find for first occurrence of a number in a set string (test='4') then use that number incremented by one and replace the remaining strings with the new value?

    Thank you for all your help,
    Max

    6,675585
    Grand MasterGrand Master
    6,675585

      Mar 16, 2009#2

      No problem.

      Code: Select all

      if (UltraEdit.document.length > 0) {
         UltraEdit.insertMode();
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
         UltraEdit.activeDocument.hexOff();
         UltraEdit.perlReOn();
         UltraEdit.activeDocument.top();
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=true;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         if (UltraEdit.activeDocument.findReplace.find("test='\\d+'")) {
            UltraEdit.activeDocument.endSelect();
            UltraEdit.activeDocument.key("LEFT ARROW");
            UltraEdit.activeDocument.findReplace.searchDown=false;
            UltraEdit.activeDocument.findReplace.find("\\d+")
            var sNumber = UltraEdit.activeDocument.selection;
            var nNumber = parseInt(sNumber,10);
            nNumber++;
            sNumber = nNumber.toString(10);
            UltraEdit.activeDocument.findReplace.searchDown=true;
            UltraEdit.activeDocument.findReplace.replaceAll=true;
            UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
            UltraEdit.activeDocument.findReplace.selectText=false;
            UltraEdit.activeDocument.findReplace.preserveCase=false;
            UltraEdit.activeDocument.findReplace.replace("test='\\d+'", "test='"+sNumber+"'");
         }
      }
      Best regards from an UC/UE/UES for Windows user from Austria

      74
      Advanced UserAdvanced User
      74

        Mar 16, 2009#3

        This is great! Thank you!

        So I have 300 files to run this on. What would be the best way to do it?

        smiles,
        Max

        6,675585
        Grand MasterGrand Master
        6,675585

          Mar 18, 2009#4

          Here is the full script without the source code of function GetListOfFiles. You have to copy the source code of function GetListOfFiles into that script file. And copy only the source code of the function without the code for demonstrating the usage of GetListOfFiles below the function GetListOfFiles.

          You can't run another script from within a script. There is no command yet to include or run another script from within a script. Also selecting the entire line with a full file name is not what I have written. By selecting an entire line you select also carriage return and line-feed and these characters are not part of the file name and make the file name invalid.

          I have not tested if the script below works. You have to enter the directory path and the file type. You should have open the output window when you develop a script to see possible error messages from the script interpreter.

          Code: Select all

          UltraEdit.insertMode();
          if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
          else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
          UltraEdit.perlReOn();
          if (GetListOfFiles(0,"???full directory path with \\ for every backslash ???","??? file type ???",false)) {
          
             var nListFile = 0;
             var nNumber   = 0;
             var sNumber   = "";
             var sFileName = "";
          
             while (nListFile < UltraEdit.document.length) {
                if (UltraEdit.document[nListFile].path == UltraEdit.activeDocument.path) break;
                nListFile++;
             }
          
             while (!UltraEdit.activeDocument.isEof()) {
                UltraEdit.activeDocument.startSelect();
                UltraEdit.activeDocument.key("END");
                sFileName = UltraEdit.activeDocument.selection;
                UltraEdit.activeDocument.endSelect();
                UltraEdit.activeDocument.key("HOME");
                UltraEdit.activeDocument.key("DOWN ARROW");
                UltraEdit.open(sFileName);
                UltraEdit.activeDocument.top();
                UltraEdit.activeDocument.findReplace.searchDown=true;
                UltraEdit.activeDocument.findReplace.mode=0;
                UltraEdit.activeDocument.findReplace.matchCase=true;
                UltraEdit.activeDocument.findReplace.matchWord=false;
                UltraEdit.activeDocument.findReplace.regExp=true;
                if (UltraEdit.activeDocument.findReplace.find("test='\\d+'")) {
                   UltraEdit.activeDocument.endSelect();
                   UltraEdit.activeDocument.key("LEFT ARROW");
                   UltraEdit.activeDocument.findReplace.searchDown=false;
                   UltraEdit.activeDocument.findReplace.find("\\d+")
                   sNumber = UltraEdit.activeDocument.selection;
                   nNumber = parseInt(sNumber,10);
                   nNumber++;
                   sNumber = nNumber.toString(10);
                   UltraEdit.activeDocument.findReplace.searchDown=true;
                   UltraEdit.activeDocument.findReplace.replaceAll=true;
                   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
                   UltraEdit.activeDocument.findReplace.selectText=false;
                   UltraEdit.activeDocument.findReplace.preserveCase=false;
                   UltraEdit.activeDocument.findReplace.replace("test='\\d+'", "test='"+sNumber+"'");
                   UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
                }
                else UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                UltraEdit.document[nListFile].setActive();
             }
             UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
          }
          Best regards from an UC/UE/UES for Windows user from Austria

          74
          Advanced UserAdvanced User
          74

            Nov 20, 2009#5

            Mofi thanks so much this worked great!

              Nov 21, 2009#6

              OK Mofi, I think I'm getting much better at this!

              Your code you gave me was great for incrementing the tocvalue now I need to make a comparison script. What I'm trying to do is take in a string that has 3 parameters, file name, title, toclevel. I have a file which has this data on each line for each file 350+ files.

              So the script grabs the line, splits the parameters using the comma, and places each into an array which i then place into variables. I use these variable to first open the file, find the title, and replace the toclevel. If the title doesn't match I need to output the name of the file to the output window or a text file for further review (still working on this part).

              Right now this script cycles through the list of files and opens it, but it doesn't do anything. Can you please explain to me what I'm doing wrong?

              Thank you,
              Max

              Code: Select all

              UltraEdit.insertMode();
              if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
              else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
              UltraEdit.perlReOn();
              
                 var nXmlFile = 0;
                 var nListFile = 0;
                 var sSplit = "";
                 var sFileName = "";
                 var sTitle = "";
                 var sDocLvl = "";
              
                 UltraEdit.activeDocument.top();
                 while (nListFile < UltraEdit.document.length) {
                    if (UltraEdit.document[nListFile].path == UltraEdit.activeDocument.path) break;
                    nListFile++;
                 }
                 while (!UltraEdit.activeDocument.isEof()) {
              
              // Select everything from the beginning of the line to the end of the line.
                    UltraEdit.activeDocument.startSelect();
                    UltraEdit.activeDocument.key("END");
                    sSplit = UltraEdit.activeDocument.selection;
                    UltraEdit.activeDocument.endSelect();
                    UltraEdit.activeDocument.key("HOME");
                    UltraEdit.activeDocument.key("DOWN ARROW");
              
              /* I need to slice this string into 3 parameters using the comma as the
                 parameter indicator.
              
                 param 1 = sFileName;
                 param 2 = sTitle;
                 param 3 = sDocLvl;
              */
                    var sTocArray = sSplit.split(',');
                    sFileName = sDocArray[0];
                    sTitle = sDocArray[1];
                    sDocLvl = sDocArray[2];
              
                    for (nXmlFile = 0; nXmlFile < UltraEdit.document.length; nXmlFile++) {
                       if (UltraEdit.document[nXmlFile].path == sFileName) break;
                    }
                    if (nXmlFile < UltraEdit.document.length) UltraEdit.document[nXmlFile].setActive();
                    else UltraEdit.open(sFileName);
                    UltraEdit.activeDocument.top();
                    UltraEdit.activeDocument.findReplace.searchDown=true;
                    UltraEdit.activeDocument.findReplace.mode=0;
                    UltraEdit.activeDocument.findReplace.matchCase=true;
                    UltraEdit.activeDocument.findReplace.matchWord=false;
                    UltraEdit.activeDocument.findReplace.regExp=true;
                    if (UltraEdit.activeDocument.findReplace.find(sTitle)) {
                       UltraEdit.activeDocument.endSelect();
                       UltraEdit.activeDocument.key("LEFT ARROW");
                       UltraEdit.activeDocument.findReplace.searchDown=false;
                       UltraEdit.activeDocument.findReplace.find("level='\\d+'");
                       UltraEdit.activeDocument.findReplace.searchDown=true;
                       UltraEdit.activeDocument.findReplace.replaceAll=false;
                       UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
                       UltraEdit.activeDocument.findReplace.selectText=false;
                       UltraEdit.activeDocument.findReplace.preserveCase=false;
                       UltraEdit.activeDocument.findReplace.replace("level ='\\d+'", sDocLvl);
                       UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
                    }
                    else UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                    UltraEdit.document[nListFile].setActive();
                 }
              Text file with list of files and strings

              Code: Select all

              test.xml,title='asdfawefaw', level ='3'
              test1.xml,title='test test test', level ='9'
              test2.xml,title='test test5 test', level ='3'
              test3.xml,title='test test test', level ='5'
              test4.xml,title='test4 test test', level ='2'
              Sample text file:

              Code: Select all

              title='test test test' level ='4'
              title='test test5 test' level ='1'
              title='test test test', level ='2'

              6,675585
              Grand MasterGrand Master
              6,675585

                Nov 21, 2009#7

                Your script was okay. It did not contain any real error. But I think you have missed some facts. The script requires that the active document on start is the list file. But you have not made sure that it starts at top of the list file. And hopefully the last line of the list file has a line ending or the result would be that the script runs into an endless loop making the actions on the last line again and again.

                Your list file must contain absolute file paths. As I first run the script with the file contents you posted it did not work because UltraEdit wanted to open Test.xml in the UltraEdit program directory, but I had all files in the temp directory.

                And I suppose the last problem was the reason why it did not work for you. When you open manually a file which is opened already in UltraEdit, it gets the focus. But this does not happen when opening an already opened file from within a script. I reported already IDM that different behavior in comparison to manual opening an already opened file or when doing this from within a macro. In the script environment you must make sure by yourself with appropriate script code that a file you want to open is not opened already. If a file to open is opened already in UltraEdit, you have to make this file active with the appropriate script command instead of opening the file. In the script environment you can't expect that the already opened file gets the focus (= becomes active) and cursor is set to top of it.

                I have modified your script to set the caret in the list file to top before starting and to check on every file to open if it is not already opened.

                74
                Advanced UserAdvanced User
                74

                  Nov 30, 2009#8

                  Hi Mofi,

                  thank you for walking me through this.

                  I have a new requirement that seems to break this script, and i'm going crazy trying to figure out why it's not working. The user wants to search for the first title attribute and force a replace with the title from the array. This works, but now the toclevel replacement doesn't work. I'm not quite certain what I'm doing wrong here. I'm using UEStudio version 09.30.0.1002

                  Thank you for your help. Max

                  Code: Select all

                  UltraEdit.insertMode();
                  if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
                  else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
                  UltraEdit.perlReOn();
                  
                     var nXmlFile = 0;
                     var nListFile = 0;
                     var sSplit = "";
                     var sFileName = "";
                     var sTitle = "";
                     var sTocLvl = "";
                  
                     UltraEdit.activeDocument.top();
                     while (nListFile < UltraEdit.document.length) {
                        if (UltraEdit.document[nListFile].path == UltraEdit.activeDocument.path) break;
                        nListFile++;
                     }
                     while (!UltraEdit.activeDocument.isEof()) {
                  
                  // Select everything from the beginning of the line to the end of the line.
                        UltraEdit.activeDocument.startSelect();
                        UltraEdit.activeDocument.key("END");
                        sSplit = UltraEdit.activeDocument.selection;
                        UltraEdit.activeDocument.endSelect();
                        UltraEdit.activeDocument.key("HOME");
                        UltraEdit.activeDocument.key("DOWN ARROW");
                  
                  /* I need to slice this string into 3 parameters using the comma as the
                     parameter indicator.
                  
                     param 1 = sFileName;
                     param 2 = sTitle;
                     param 3 = sTocLvl;
                  */
                        var sTocArray = sSplit.split(',');
                        sFileName = sTocArray[0];
                        sTitle = sTocArray[1];
                        sTocLvl = sTocArray[2];
                  
                        for (nXmlFile = 0; nXmlFile < UltraEdit.document.length; nXmlFile++) {
                           if (UltraEdit.document[nXmlFile].path == sFileName) break;
                        }
                        if (nXmlFile < UltraEdit.document.length) UltraEdit.document[nXmlFile].setActive();
                        else UltraEdit.open(sFileName);
                        UltraEdit.activeDocument.top();
                        UltraEdit.activeDocument.findReplace.searchDown=true;
                        UltraEdit.activeDocument.findReplace.mode=0;
                        UltraEdit.activeDocument.findReplace.matchCase=true;
                        UltraEdit.activeDocument.findReplace.matchWord=false;
                        UltraEdit.activeDocument.findReplace.regExp=true;
                        if (UltraEdit.activeDocument.findReplace.find(title='.*?')) {
                           UltraEdit.activeDocument.endSelect();
                           UltraEdit.activeDocument.findReplace.replace("title='.*?'", sTitle);
                           UltraEdit.activeDocument.key("LEFT ARROW");
                           UltraEdit.activeDocument.findReplace.searchDown=false;
                           UltraEdit.activeDocument.findReplace.find("toclevel='\\d+'");
                           UltraEdit.activeDocument.findReplace.searchDown=true;
                           UltraEdit.activeDocument.findReplace.replaceAll=false;
                           UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
                           UltraEdit.activeDocument.findReplace.selectText=false;
                           UltraEdit.activeDocument.findReplace.preserveCase=false;
                           UltraEdit.activeDocument.findReplace.replace("toclevel ='\\d+'", sTocLvl);
                           UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
                        }
                        else UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                        UltraEdit.document[nListFile].setActive();
                     }
                  Here's sample to put in array

                  Code: Select all

                  C:\GAMES\TEST.xml,title='Game to Space',toclevel='3'
                  C:\GAMES\TEST2.xml,title='Gamers System',toclevel='2'
                  C:\GAMES\TEST3.xml,title='Identify Game Creation',toclevel='4'
                  Here's same of xml file that should be changed:

                  Code: Select all

                  title='test test test' level ='4'
                  title='test test5 test' level ='7'
                  title='test test test', level ='9'

                  6,675585
                  Grand MasterGrand Master
                  6,675585

                    Dec 01, 2009#9

                    Here is the script which works for your sample files.

                    Code: Select all

                    UltraEdit.insertMode();
                    if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
                    else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
                    UltraEdit.perlReOn();
                    
                       var nXmlFile = 0;
                       var nListFile = 0;
                       var sSplit = "";
                       var sFileName = "";
                       var sTitle = "";
                       var sTocLvl = "";
                       var sLowerCaseFileName = "";
                    
                       UltraEdit.activeDocument.top();
                       while (nListFile < UltraEdit.document.length) {
                          if (UltraEdit.document[nListFile].path == UltraEdit.activeDocument.path) break;
                          nListFile++;
                       }
                       while (!UltraEdit.activeDocument.isEof()) {
                    
                    // Select everything from the beginning of the line to the end of the line.
                          UltraEdit.activeDocument.startSelect();
                          UltraEdit.activeDocument.key("END");
                          sSplit = UltraEdit.activeDocument.selection;
                          UltraEdit.activeDocument.endSelect();
                          UltraEdit.activeDocument.key("HOME");
                          UltraEdit.activeDocument.key("DOWN ARROW");
                    
                    /* I need to slice this string into 3 parameters using the comma as the
                       parameter indicator.
                    
                       param 1 = sFileName;
                       param 2 = sTitle;
                       param 3 = sTocLvl;
                    */
                          var sTocArray = sSplit.split(',');
                          sFileName = sTocArray[0];
                          sTitle = sTocArray[1];
                          sTocLvl = sTocArray[2];
                          sLowerCaseFileName = sFileName.toLowerCase();
                    
                          for (nXmlFile = 0; nXmlFile < UltraEdit.document.length; nXmlFile++) {
                             // String compares are case sensitive. Therefore better make always
                             // both file names lowercase and then compare the file names.
                             if (UltraEdit.document[nXmlFile].path.toLowerCase() == sLowerCaseFileName) break;
                          }
                          if (nXmlFile < UltraEdit.document.length) UltraEdit.document[nXmlFile].setActive();
                          else UltraEdit.open(sFileName);
                          UltraEdit.activeDocument.top();
                          UltraEdit.activeDocument.findReplace.searchDown=true;
                          UltraEdit.activeDocument.findReplace.mode=0;
                          UltraEdit.activeDocument.findReplace.matchCase=true;
                          UltraEdit.activeDocument.findReplace.matchWord=false;
                          UltraEdit.activeDocument.findReplace.regExp=true;
                          if (UltraEdit.activeDocument.findReplace.find("title='.*?'")) {
                             UltraEdit.activeDocument.write(sTitle);
                             if (UltraEdit.activeDocument.findReplace.find("level ='\\d+'")) {
                                UltraEdit.activeDocument.write(sTocLvl);
                             }
                             // If the XML file was already open and it was in the file tab sequence
                             // left the list file, the document number of the list file would change
                             // when closing now the XML file. So better just save the XML file in this
                             // case and let the file open.
                             if (nXmlFile > nListFile) UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
                             else UltraEdit.save();
                          }
                          else {
                             if (nXmlFile > nListFile) UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                          }
                          UltraEdit.document[nListFile].setActive();
                       }
                    First I have had a problem when the first of the 3 XML files was opened already. The reason was that I have given the first file the name Test.xml instead of TEST.xml as written in the list file. While Windows file systems are not case sensitive, the string compares in Javascript are case sensitive and so the script has not detected that Test.xml was opened already. I fixed this problem as you can see on my comments in the for loop.

                    The second problem I have had was when Test.xml was left the list file in the file tab order. Closing the XML file after modifying it causes in this case the remaining documents to renumber and as I found out UltraEdit v15.20.0.1022 (= UEStudio v9.30.0.1002) has a problem to update all document array properties immediately. So I added code to not close already opened and modified XML files left the list file and just save them to avoid problems with document array changes left the list file.

                    In your script you made the mistake that the first search string is not enclosed in double quotes. Also the the XML files contain "level =" and not "toclevel =" and therefore the second replace never found the string to replace.

                    As you can see I changed those replaces in my version of the script completely by just searching twice for the string of interest and overwriting the found and selected strings by the strings from the list file. I do this because I know that UE v15.20.0.1022 / UES v9.30.0.1002 have the problem that replaces do not work in Unicode files and XML files are often encoded in UTF-8. The problem with replaces from within scripts in Unicode files not working was already reported by me to IDM and confirmed by IDM support. Because this is a serious bug I expect a fix of this bug in next released version of UltraEdit / UEStudio.activeDocument

                    74
                    Advanced UserAdvanced User
                    74

                      Dec 01, 2009#10

                      Mofi, thank you so much. I really appreciate how detailed you are in explaining all of this.

                      Mofi, could you please explain this more. I'm not quite sure I understand it.

                      Code: Select all

                      for (nXmlFile = 0; nXmlFile < UltraEdit.document.length; nXmlFile++) {
                          if (UltraEdit.document[nXmlFile].path === sFilePath) break;
                       }
                      if (nXmlFile < UltraEdit.document.length) UltraEdit.document[nXmlFile].setActive();
                       else UltraEdit.newFile();

                      6,675585
                      Grand MasterGrand Master
                      6,675585

                        Dec 02, 2009#11

                        That code snippet is not part of my scripts and contains also an error: ===

                        I have used in the last script following code snippet now with detailed comments:

                        Code: Select all

                        sLowerCaseFileName = sFileName.toLowerCase();
                        
                        // Scan in the array of opened files if the next file from the list is already opened in UE / UES.
                        for (nXmlFile = 0; nXmlFile < UltraEdit.document.length; nXmlFile++) {
                           // String compares are case sensitive. Therefore better make always both file names lowercase
                           // and then compare the file names. For example the list file could contain TEST.xml, but the
                           // real file name is Test.xml and Test.xml is already open. When just comparing the file names
                           // case sensitive without making both lowercase, "TEST.xml" is different "Test.xml" and this
                           // loop would therefore not detect that the file Test.xml is already open. For Linux that
                           // would be correct, but not for Windows because Windows file systems are not case sensitive.
                           if (UltraEdit.document[nXmlFile].path.toLowerCase() == sLowerCaseFileName) break;
                        }
                        // If the loop variable is smaller the number of opened files, the file to open next
                        // is already opened and therefore this file must just be set the active file. Otherwise
                        // the file must be opened and becomes then automatically the active file. This is a
                        // different behavior in opening a file from within a script in comparison to opening
                        // a file manually. When manually opening a file which is already open, UltraEdit does
                        // not load it (and discards all modifications), it just makes the file active. But
                        // opening a file from within a script which is already opened does not make the file
                        // active. Therefore this code is necessary to continue the script on the correct file
                        // when one or more files from the list file are already opened in UltraEdit / UEStudio.
                        if (nXmlFile < UltraEdit.document.length) UltraEdit.document[nXmlFile].setActive();
                        else UltraEdit.open(sFileName);
                        Best regards from an UC/UE/UES for Windows user from Austria

                        74
                        Advanced UserAdvanced User
                        74

                          Dec 03, 2009#12

                          Mofi thank you it's much clearer now.

                          2
                          NewbieNewbie
                          2

                            Aug 28, 2011#13

                            Help me, please :)

                            I have HTML file with some <p> tags, which matches numbers of pages of scanning book:

                            Code: Select all

                            <p>5</p>
                            <p>text</p>
                            <p>6</p>
                            <p>text</p>
                            <p>7</p>
                            <p>text</p>
                            <p>8</p>
                            etc.

                            I need increment all numbers in <p> tags with such result:
                            <p>5+1</p>
                            <p>text</p>
                            <p>6+1</p>
                            <p>text</p>
                            etc.

                            I tried (<p>([0-9]+)</p>) and increment RegExp.$1 or /1 for this task.

                            I read post above, but I don't know how write value ([0-9]+) or $1

                            6,675585
                            Grand MasterGrand Master
                            6,675585

                              Aug 28, 2011#14

                              A regular expression replace can only find text and replace it with another text. But it can't convert a string to a number, increment the number, convert the number back to string and replace the found number string with the new number string. That can be only done with a script.

                              Code: Select all

                              if (UltraEdit.document.length > 0) {
                                 UltraEdit.insertMode();
                                 if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
                                 else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
                                 UltraEdit.activeDocument.hexOff();
                                 UltraEdit.perlReOn();
                                 UltraEdit.activeDocument.top();
                                 UltraEdit.activeDocument.findReplace.mode=0;
                                 UltraEdit.activeDocument.findReplace.matchCase=false;
                                 UltraEdit.activeDocument.findReplace.matchWord=false;
                                 UltraEdit.activeDocument.findReplace.searchDown=true;
                                 UltraEdit.activeDocument.findReplace.regExp=true;
                                 while (UltraEdit.activeDocument.findReplace.find("(?<=<p>)\\d+(?=</p>)")) {
                                    var sNumber = UltraEdit.activeDocument.selection;
                                    var nNumber = parseInt(sNumber,10);
                                    nNumber++;
                                    UltraEdit.activeDocument.write(nNumber.toString(10));
                                 }
                                 UltraEdit.activeDocument.top();
                              }
                              The script uses a Perl regular expression string with a zero character consuming lookbehind (?<=<p>) and a zero character consuming lookahead (?=</p>) to select only the number string \d+ (second backslash because of javascript) between the paragraph tags. This decimal (base 10) number string is converted to an integer, incremented and converted back to a string which overwrites the found and selected number string.

                              2
                              NewbieNewbie
                              2

                                Aug 28, 2011#15

                                It works. Many thanks!