2 Replies Latest reply on Apr 12, 2013 4:01 AM by Muthuraj Durairaj

    Updating hyperlink using GREP adding extra back slash in the replacement text

    Muthuraj Durairaj Level 1

      Hi All,

       

      I am trying the following code to update the existing URLs to match with the new publication number. The presence of "4AA3-1234ENW" has to be updated with "4AA3-1234ENN" (the last character changing to "N" and this is the only change need to be done). Earlier I tried to find the actual URL and tried to change the last character to "N". Due to some grep find and change difficulties and posted (http://forums.adobe.com/message/5225283#5225283), bad luck I havenot received any reply so far.

       

      I did an another attempt with different approach as the actual publication number is there in the document. I take it by GREP find and stores that value and update the URLS with that value.

       

      It is working fine, but it adds an extra slash before and after the replacment

       

      Original: http://twitter.com/home/?status=Modernize+%40+http%3A%2F%2Fh20195.www.xxx.com%2FV2%2FGetDo cument.aspx?docname=4AA3-9539ENW   

      Replaced: http://twitter.com/home/?status=Modernize+%40+http%3A%2F%2Fh20195.www.xxx.com%2FV2%2FGetDo cument.aspx?docname=/4AA3-9539ENN/   

       

      Please help me on this. Its almost done. Still I prefer to find and change the URLs directly as tried earlier, as this method may change any other URLs than the targeted one, I afraid.

       

      Please help me to avoid this extra back slash being added.

       

      //CHANGE SOME ICON URLS FROM ENW TO ENN
      
      
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences = NothingEnum.nothing;
      
      
      // grep find/change
      app.findGrepPreferences = app.changeGrepPreferences = null;       
      app.findGrepPreferences.findWhat = "(\\d+\\u+\\d+-\\d+\\u{2})(\\u+)";
      app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Back page"). paragraphStyles.item("Legal_7/9");
      app.changeGrepPreferences.changeTo = "$1N";
      app.changeGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyleGroups.item("Back page"). paragraphStyles.item("Legal_7/9");
      var myFindpubnumber = app.activeDocument.findGrep();  
      var myOldPubnumber = myFindpubnumber[0].contents;
      
      
      alert (myOldPubnumber);
      
      
      var myChangepubnumber = app.activeDocument.changeGrep();  
      var myNewPubnumber = myChangepubnumber[0].contents;
      
      
      alert (myNewPubnumber);
      
      
      // clear grep prefs
      app.findGrepPreferences = app.changeGrepPreferences = null;
      
      
          var RateItgrepForFind = RegExp(myOldPubnumber,"g");
                var RateItgrepForReplace = RegExp(myNewPubnumber);
      
      
                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);
                }