17 Replies Latest reply: Jul 27, 2012 6:16 AM by [Ariel] RSS

    GREP Help

    [Ariel] Community Member

      Hello,

       

      For once, my editor behaved herself and enclosed all block-quotes in

      tags.  tags?

       

      Thanks,

      Ariel

       

        • 1. Re: GREP Help
          Peter Spier ACP/MVPs

          What's the question, and what sort of tags?

          • 2. Re: GREP Help
            bill_t12

            Not real clear on exactly what you want to have happen.

             

            Just guessing, but if you put this in the Find What field …

             

            (tag)(.)

             

            … and replace where it says tag with the actual tag (if they used square brackets [Block] you'll need to escape from them with backslashes … \[Block\])

             

            Put $2 in the Change To field …

             

            … and then your Block Quote style in the Change Format field.

             

            It'll look for your Tag and the next character following it and then replace them both with the following character only and bring in the style with it.

             

            Or maybe you had a different question.

            • 3. Re: GREP Help
              [Ariel] Community Member

              It wasn't clear? I'll try again.

               

              Sample text (including the tags):

               

               

               

              I'm trying to grep all the text between the first tag in angle brackets

              and the final tag in angle brackets, even if this spans more than one

              paragraph. So in the above example, I want to get all the text from the

              first "this" through to the last "quote." In this case that is 2 paragraphs.

               

              How would I grep such a thing?

               

              Thanks,

              Ariel

              • 4. Re: GREP Help
                [Ariel] Community Member

                Thanks bill.

                 

                No, that's not what I meant. I must be explaining this very badly. I

                simply want to find all text between  even when it spans

                multiple paragraphs.

                 

                Is this an email problem? I'm sending this post via email, and it could

                be that the tags are coming out in the Forum as formatting instead of

                plain text?

                 

                Thanks,

                Ariel

                • 5. Re: GREP Help
                  [Ariel] Community Member

                  I think the email is screwing things up here, so I'm going to ask this a

                  different way.

                   

                  I want to search for all the text between the word Elephant and the word

                  Tiger in the following text

                   

                  Elephant is an animal with a trunk

                  An animal with stripes is a tiger

                   

                  What grep expression can I use that will find all the text between

                  Elephant and Tiger?

                   

                  Thanks,

                  Ariel

                  • 6. Re: GREP Help
                    bill_t12 Community Member

                    Hi Ariel,

                     

                    There isn't any sample text coming through at all.

                     

                    Try this in the Find Field:

                     

                    (<TAG>)(.+\r*.*\r*.*\r*.*)(<\\TAG>)

                     

                    So that's three sub-expressions.

                     

                    1. The first one will find the opening tag;
                    2. the second one will find any character one or more times, followed by a return zero or more times, followed by any character zero or more times (and again two more times — that's 4 paragraphs worth, add more \r*.* sections as needed);
                    3. the third one will find the closing tag.

                     

                    And $2 in the change field will replace all of it with just the content of the second string. Change format to the style you want.

                    • 7. Re: GREP Help
                      [Ariel] Community Member

                      Got it. Something like this seems to work:

                       

                      (elephant)(.|\r)+?(tiger)

                       

                      Thanks.

                       

                      Ariel

                      • 8. Re: GREP Help
                        [Ariel] Community Member

                        Thanks very much Bill.

                         

                        This email interface could do with some work. If I had Internet access

                        right now I would use it and stop making people double-guess.... But I

                        don't right now.

                         

                        Anyway, I figured out that I could use a | (or) sign, and that gives as

                        many paragraphs as needed. Plus a non-greedy ? so that it stops as soon

                        as it reaches the first end-tag. Pretty much the same as you solution,

                        but a bit more efficient perhaps.

                         

                        Thanks again for your time and help,

                        Ariel

                        • 9. Re: GREP Help
                          Peter Spier ACP/MVPs

                          (?s)(<tag>)(.+?)(<tag>)

                           

                          Replace with $2

                           

                          This turns on Single Line Mode so it ignores the ends of paragraphs, but also looks for the shortest match so it will capture the the paragraphs, or groups of paragraphs, separately. Otherwise it would find everything between the first and last tag as one match.

                          • 10. Re: GREP Help
                            bill_t12 Community Member

                            Much tidier but you need to use a close tag in the last sub-expression.

                            • 11. Re: GREP Help
                              [Ariel] Community Member

                              Thanks Peter.

                               

                              I played around with multiline mode (?m). That seemed more intuitive to

                              me but it didn't work. In the end I found a slightly different solution

                              to yours. I can't say I really understand what single line and multi

                              line modes do...

                               

                              Many thanks,

                              Ariel

                              • 12. Re: GREP Help
                                Peter Spier ACP/MVPs

                                bill_t12 wrote:

                                 

                                Much tidier but you need to use a close tag in the last sub-expression.

                                Don't know what you're seeing that's missing. Works fine just as I pasted it and it appears on the web page here.

                                 

                                Or are you thinking I meant html style tags: <tag> and </tag>? <tag> is just a placeholder for whatever the editor used...

                                • 13. Re: GREP Help
                                  bill_t12 Community Member

                                  I was thinking that the editor used a different tag to close the quote.

                                   

                                  The way I was reading things it seemed like the search would go from the first open tag to the next open tag.

                                  • 14. Re: GREP Help
                                    Peter Spier ACP/MVPs

                                    Yeah, I can see how it was confusing. I made the assumption, perhaps false, that Ariel understood he should substitute the correct tags.

                                    • 15. Re: GREP Help
                                      [Ariel] Community Member

                                      Thank you both.

                                       

                                      I get the feeling that I've been producing a bunch of blank posts.

                                       

                                      I think I'll have to give up on using email with the forums soon.

                                       

                                      Problem solved with regards the GREP though!

                                       

                                      Thanks,

                                      Ariel

                                      • 16. Re: GREP Help
                                        [Jongware] MVP

                                        Arïel wrote:

                                         

                                        I played around with multiline mode (?m). That seemed more intuitive to

                                        me but it didn't work. In the end I found a slightly different solution

                                        to yours. I can't say I really understand what single line and multi

                                        line modes do...

                                         

                                        Single line mode (?s) changes the behavior of the . (period) operator. By default it's disabled and does not match a hard return, so the expression

                                         

                                        .+

                                         

                                        will always stop matching right before the next hard return. Enabling single line mode will essentially make your text one full long line, as far as the . wildcard is concerned.

                                         

                                        You typically need this modifier if you want to grab a match over multiple paragraphs.

                                         

                                        Multiple line mode (?m) changes the behavior of the ^ and $ anchor points. By default it is enabled and matches the start and end of a paragraph (right after and before a hard return). Disabling will make ^ and $ only match the very start and the very end of an entire story (the largest single unit of consecutive text in InDesign).

                                         

                                        This sounds weird because it seems like the default mode is "normal", and therefore there would be no use to be able to disable this flag. However, originally GREP was designed for simple text line processing, inside of which you'd never would find a hard return. When support for hard returns as 'end of paragraph' got added, GREP needed a modifier to discern between start-of-text and start-of-new-paragraph.

                                         

                                        InDesign supports \A and \Z for start and end of story, so you don't need to change this flag, but you get it for free anyway because it's built in into the standard GREP library that Adobe used.

                                        • 17. Re: GREP Help
                                          [Ariel] Community Member

                                          Thanks Jongware, that's a useful explanation. ?s will definitely come in handy.

                                           

                                          Thanks everyone for helping. Email-posed questions can't be marked as answered, but your help is much appreciated.

                                           

                                          Ariel