6 Replies Latest reply: Feb 26, 2013 9:54 AM by Joel Cherney RSS

    how to find text between TWO consecutive tabs and a return…

    Matthew Appleton

      Hello – - this great script finds all the text after a tab and before a return. Works like a dream in my paragraph style, thank you…

      (?<=\t).*?(?=\r)

      What I woudl love to find out is how to tune the script to find all the text between TWO consecutive tabs and a return…

      Would be incredibly useful; trying to assign a character style to numbers in an index…

      thanks for your time and assistance!

       

       

      Original script found here:

      http://indesignsecrets.com/findbetween-a-useful-grep-string.php/comment-page-2#comment-550 882

        • 1. Re: how to find text between TWO consecutive tabs and a return…
          P Spier CommunityMVP

          Try (?<=\t{2}).*?(?=\r) or (?<=\t\t).*?(?=\r)

          • 2. Re: how to find text between TWO consecutive tabs and a return…
            P Spier CommunityMVP

            That finds text after two tabs with nothing between them, which is how I interpret two consecutive tabs. If that's not waht you meant, you'll need to provide a clearer explanation.

            • 3. Re: how to find text between TWO consecutive tabs and a return…
              Matthew Appleton Community Member

              Hi, and thanks for the reply... These dont seem to work unfortunately, perhaps it helps if you look at the structure of the text below...

              my index is currently formatted

               

              tab #1 / text string / tab #2 / string of page numbers and commas / return

               

              I am trying to assign a character style JUST to the text after the second tab...

               

              Screen Shot 2013-02-26 at 00.26.12.png

              • 4. Re: how to find text between TWO consecutive tabs and a return…
                Joel Cherney CommunityMVP

                It's not a "script" but a GREP query. If your post tells us all of the conditions, then you don't need GREP at all. A nested character style will work just fine:

                 

                nest.png

                If there's no forced line break, it'll continue applying the character style through the end of the paragraph. If you need it to continue through a forced line break, use an End Nested Style character instead.

                • 5. Re: how to find text between TWO consecutive tabs and a return…
                  Matthew Appleton Community Member

                  Beautiful! Thanks for the advice, you are right I was getting confused with GREP, although it was getting close to doing my bidding!

                   

                  Your suggestion works like a dream once edited as per the image below

                   

                  Screen Shot 2013-02-26 at 01.19.01.png

                  • 6. Re: how to find text between TWO consecutive tabs and a return…
                    Joel Cherney CommunityMVP

                    I think it's still worthwhile to figure out the GREP query that will work, but I always like to get the job done first, and then have fun stretching my brain to write the GREP query. Because I find writing GREP queries fun the same way that some people like to do crossword puzzles.

                     

                    One script that I'd suggest that you download and install, if you like stretching your cranium by writing GREP queries, is WhatTheGREP written by estimable forums regular [Jongware]. It does a fine job of expanding GREP queries into something approaching plain English.

                     

                    (?<=\t).*?(?=\r)

                     

                    Anyhow, what you have here is this query

                     

                    .*?           (which means "find any group of zero or more characters, grab the shortest match")

                     

                    sandwiched in between a lookahead group and a lookbehind group. The first looks for a tab (that is \t) and the second looks for a hard return (that is \r). The advantage of lookahead and lookbehind is that you can look for stuff that is next to a tab without actually looking for the tab. So, all you have to do to turn your query into what you were originally asking for is to change the trailing \r into a \t

                     

                    (?<=\t).*?(?=\t)

                     

                    which means "find the smallest amount of text possible between two tabs in a single paragraph."

                     

                    *     *     *     *     *    

                     

                    So, which is better, a nested style or a GREP query, or a GREP style? The reason I suggested a nested style is that I use 'em all the time when I have a project that has an index. A GREP find/replace query makes a permanent change to the index, but if I regenerate the index, I have to remember to re-run the find/replace query. I'd rather fob off the job of remembering stuff to a robot, and save my brain for more exciting tasks, like talking to my coworkers about social science research or Dwarf Fortress. So, it's going to be some kind of automatically applied style. Nested styles take less computing power to apply than do GREP styles. So I chronically advise people to use nested styles in this case, as it is the least taxing solution for your brain and for your computer.