2 Replies Latest reply on Jun 29, 2012 2:35 AM by csm_phil

    Problem with GREP finding

    Techi Panda Level 2

      Hi Experts

       

      I am trying to find text using GREP option:

       

      <k6>

      para 1

      para 2

      para 3

      </k6>

       

      using this grep function

       

      app.findGrepPreferences = app.changeGrepPreferences = null;

      app.findGrepPreferences.findWhat = "(?s)<k6>\r(.+?\r)</k6>";

      var myResults = app.activeDocument.findGrep();

       

      while I am executing this script the end of paragraph marker "\r" automatically changed to SPACE( ) in the FIND/CHANGE dialogue box. If i change the space manually to \r in find/change dialogue box it works fine. Why executing from script this changes happen? Any one experienced this before.

       

      Kindly suggest.

       

      Thanks in advance

        • 1. Re: Problem with GREP finding
          [Jongware] Most Valuable Participant

          You mean the input appears to have changed to a space when you check what's in the Find box? That is normal behavior. Since you are using Javascript strings, codes such as "\t" and "\r" are *immediately* translated into their literal characters *before* being processed any further. So you don't write "\r" into the Find dialog, you are writing a literal hard return character. The Find/Change dialog cannot show that character on screen so it displays a space.

           

          You say "if I change it to \r it works fine" -- do you mean that it does *not* work if you leave it that way? Because it should work just fine. (And you actually can have a little fun by inserting all kinds of 'special' characters literally into the Find dialog -- try tab or newline.)

           

          But if it bothers you for cosmetic reasons, use "\\r" instead. The double backslash is also a special Javascript string escape and will be replaced (immediately) with a single backslash. Then the string that goes into the Find dialog is "\r", and that's what InDesign is going to translate back to a hard return when it's processing your find string.

          • 2. Re: Problem with GREP finding
            csm_phil Level 4

            Hi Panda,

             

             

            The above jongware given breif details about your mistake and clear your probs.

             

            I have modified you code, please try the below JS code.

             

             

            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.findWhat = "(?s)<k6>\\r(.+?\\r)</k6>";
            var myResults = app.activeDocument.findGrep(); 
            app.select(myResults);
            

             

             

            thx

            csm_phil

            1 person found this helpful