7 Replies Latest reply on Mar 29, 2010 1:29 AM by anabasa@hotmail.com

    Selecting more than one paragraph with GREP

    anabasa@hotmail.com

      Hi all

      I'm having some trouble with a GREP search in JavaScript.

      The following expression is ment to find any text with a certain paragraph style that starts with "Note:". As you can imagine, the expression is ment to find info notes that may be isolated or be followed by another note, in which case, the second note should not be included in the selection.

       

      (^Note:)(.+)((.+)(\r)(^Note:)(.+))*

       

      Now, when I try the expression in the GREP Find/Change in InDesign it works fine but, when I put it in the script it only selects a single paragraph. Is there any way of selecting more than one paragraph??

       

      thanx

        • 1. Re: Selecting more than one paragraph with GREP
          Peter Kahrel Adobe Community Professional & MVP

          You probably forgot to escape the backslash. So instead of \r try \\r

           

          Peter

          • 2. Re: Selecting more than one paragraph with GREP
            anabasa@hotmail.com Level 1

            Thanks for the response Peter, but no, I didn't.

             

            I'm wondering if my problem is just because I'm looking for a certain Paragraph Style, rather than character style... Could that be the proble?? and, if so, how can I get over it?? I still need to search for the paragraph style....

            • 3. Re: Selecting more than one paragraph with GREP
              [Jongware] Most Valuable Participant

              A couple of observations:

               

              You are using a lot of extra parentheses which are not necessary. It makes everything a bit more muddy than it already is ... For example, instead of

               

              (.+)(\r)

               

              use

               

              (.+\r)

               

              ... or be followed by another note, in which case, the second note should not be included in the selection ..

               

              Were you expecting the second (^Note:) to not include that text? Because it does -- (^...) is not a Negate function. If it did work, it would include "Note:" at the start of the next line, and since the previous character already is an "\r" the "^" is, at best, obsolete, and at worst, it may throw off GREP and thus work not at all.

               

              Now, when I try the expression in the GREP Find/Change in InDesign it works fine ...

               

              It doesn't -- not on a few paragraphs I tried it on, with and without "Note:" in front. It only finds the next entire paragraph starting with "Note:"

              Can you give a sample text where it does work, and where it doesn't but should?

               

              This appears to work:

               

              ^Note:.+(\r(?!Note:).+)*

               

              -- it will find "Note:", followed by any number of next paragraphs in the same style that not start with "Note" again. Is this what you were after?

              • 4. Re: Selecting more than one paragraph with GREP
                anabasa@hotmail.com Level 1

                Thanks a lot for the answer, Jongware

                 

                To be honest, I have no idea as to why I used that many parentheses, but I did take your advice into account.

                 

                I cleared the extra parentheses just as you sugensted. But that does no seem to be the (only?) problem. It still selects only the first paragraph of a note, rather than the three it actually has (in my test example, that is). The thing is that I search for a certain Paragraph Style, rather than a Character style, and that might be the problem. Could it just be that javascript does not search like InDesign does?.

                 

                I simply can't make the script work properly...

                • 5. Re: Selecting more than one paragraph with GREP
                  [Jongware] Most Valuable Participant

                  It works from within a script as well for me. I tested with this text:

                   

                  Note: dis is a note.

                  Dis is too.

                  Note: don’t pick up this one.

                   

                  -- all in the same style. This script found, and changed, only the first two lines:

                   

                  app.findGrepPreferences.findWhat = "^Note:.+(\\r(?!Note:).+)*";
                  app.findGrepPreferences.appliedParagraphStyle = "note style";
                  result = app.activeDocument.findGrep();
                  result[0].underline = true;
                  

                   

                  -- it found this:

                   

                  note.png

                   

                  -- and a Find Next, or changing the script to "result[1].underline = true;" correctly marks the second line as well.

                   

                  So there must be something wrong elsewhere in your version.

                  • 6. Re: Selecting more than one paragraph with GREP
                    [Jongware] Most Valuable Participant

                    An interesting variant of the above expression:

                     

                    (?s)^Note:(.(?!Note:))*

                     

                    Given a text:

                     

                    Note:

                    Note: this too.

                     

                    this one will find the first "Note:" and its two following hard returns, after that the next "Note:". My previous GREP would only find the second note.

                    • 7. Re: Selecting more than one paragraph with GREP
                      anabasa@hotmail.com Level 1

                      Ok, so I definitely was wrong.

                      I'm trying to modify a script so adjust it to my needs and, for some reason, it didn't work with your expression. I tried your piece of scritp, though, and decided to somehow restart the script.

                       

                      I'll just have to overcome my scripting inutility.

                       

                      Thanx a lot, nevertheless!