1 Reply Latest reply on Apr 11, 2013 3:35 AM by Muthuraj Durairaj

    Find and change hyperlinks using GREP query

    Muthuraj Durairaj Level 1

      Hi All,

       

      I am trying to find and replace part of a hyperlink. Below is the code I tried (found and modified. thanks to whoever written this). It is working fine. However, I need to find and change only the last part of the URL (4AA3-9539ENW) since it is changing document to document.

       

      The only change in the URL is 4AA3-9539ENW to 4AA3-9539ENN (just to change ENW to ENN). How to find this using GREP?

       

      I tried "http:\/\/deploy.ztelligence.com\/start\/index\.jsp\?PIN=168M59L2W4H8Z\&filename=(\d+\u+\ d+-\d+\u+)(W)" with "$1N".

       

      It was working fine in find and change window in Indesign. And I am not too sure how to bring this GREP query in to the following set of code. There are 4 instances of these kind of URL need to be changed.

       

      Please help me on this. Thanks in advance.

       

       

         var RateItgrepForFind = "http://deploy.ztelligence.com/start/index\.jsp\?PIN=168M59L2W4H8Z&filename=4AA3-9539ENW";
         var RateItgrepForReplace = "http://deploy.ztelligence.com/start/index\.jsp\?PIN=168M59L2W4H8Z&filename=4AA3-9539ENN";
      
                var dests = app.documents[0].hyperlinkURLDestinations.everyItem().getElements();
                for(var i=0;i<dests.length;i++){
                          dests[i].destinationURL = dests[i].destinationURL.replace(RateItgrepForFind,RateItgrepForReplace);
                }
      

       

       

      Regards,

      Muthuraj. D

        • 1. Re: Find and change hyperlinks using GREP query
          Muthuraj Durairaj Level 1

          Hi,

           

          I have found following code snippet in one of the post (Thanks to Jongware).

           

          Can you please help me on how to use this to suite my requirement.

           

          // use your standard GREP search & replace

              app.changeGrepPreferences = null;

              app.findGrepPreferences = null;

              // note ? mark in following GREP search string, the non-greedy modifier. Thanks Jongware!

              var myString = "app.findGrepPreferences.properties = {findWhat:\"<>(.*?)<\/>\"};";

              myString += "app.changeGrepPreferences.properties = {changeTo:\"$1\", appliedCharacterStyle:\""+characterStyle+"\"};";

              myString += "app.findChangeGrepOptions.properties = {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true};";

              app.doScript(myString, ScriptLanguage.javascript);

              var myFoundItems = docRef.changeGrep();

              //Reset the find/change grep preferences after each search.

              app.changeGrepPreferences = null;

              app.findGrepPreferences = null;

           

           

          I tried the following.

           

          var RateItgrepForFind = "app.findGrepPreferences.properties = {findWhat:\"(\\d+\\u+\\d+-\\d+\\u+)(W)};";

          var RateItgrepForReplace = "app.findGrepPreferences.properties = {changeTo:\"$1N};";

           

           

          But it is not working. Please help.

           

          Regards,

          Muthuraj. D