2 Replies Latest reply on Sep 12, 2016 4:33 AM by jakec88782761

    Using GREP in Indesign scripts

    jakec88782761 Level 1

      Hi Guys,

       

      I've got this script which is trying to apply a couple of GREPs at once. From what I can tell it should work but for some reason my GREP expressions throw an error.

      Can anyone give me some advice as to why it doesn't work?

       

      function proofread () {
         
          app.findGrepPreferences=app.changeGrepPreferences=null;
         
          app.findGrepPreferences.findWhat= "the\s+?(section\s+?\t+?\d+?[.?\d+]?)";
          app.changeGrepPreferences.changeTo="$1";
         
         
         
          app.activeDocument.changeGrep();
         
          app.findGrepPreferences=app.changeGrepPreferences=null;
         
          app.findGrepPreferences.findWhat="(?i)activity\s+?level";
          app.changeGrepPreferences.changeTo="Activity\sLevel";
         
          app.activeDocument.changeGrep();
          }

      proofread();

       

      Thanks in advance

        • 1. Re: Using GREP in Indesign scripts
          Sajeev Sridharan Level 4

          Try this,

           

          function proofread () {
              app.findGrepPreferences=app.changeGrepPreferences=null;
              app.findGrepPreferences.findWhat= "the\\s+?(section\\s+?\\t+?\\d+?[.?\\d+]?)";
              app.changeGrepPreferences.changeTo="$1";
              app.activeDocument.changeGrep();
              
              app.findGrepPreferences=app.changeGrepPreferences=null;
              app.findGrepPreferences.findWhat="(?i)activity\\s+?level";
              app.changeGrepPreferences.changeTo="Activity\\sLevel";
              app.activeDocument.changeGrep();
              app.findGrepPreferences=app.changeGrepPreferences=null;
              }
          proofread();
          
          

           

           

          Alternate method:

           

          findChange("the\\s+?(section\\s+?\\t+?\\d+?[.?\\d+]?)", "$1");
          findChange("(?i)activity\\s+?level", "Activity\\sLevel");
          
          
          function findChange(findWhat, changeTo) {
              app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
              if (findWhat) {
                  app.findGrepPreferences.findWhat = findWhat;
              }
              if (changeTo) {
                  app.changeGrepPreferences.changeTo = changeTo;
              }
              app.activeDocument.changeGrep();
              app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
          }
          
          • 2. Re: Using GREP in Indesign scripts
            jakec88782761 Level 1

            Wow thanks Sajeev.

            You even managed to make the script easier to read!

             

            So is it Javascript in general where you have so double \\ to escape characters using GREP?