17 Replies Latest reply on Sep 10, 2015 12:35 PM by Obi-wan Kenobi

    GREP expression to find a line with no colon

    dooalot Level 1

      Hello all,

      I've been using GREP more and more for styling text and I really love it. In most cases I have been able to figure out how to write expressions to do what I need, but right now this one escapes me. I want to apply a character style to lines of text that DO NOT contain a colon. I've tried a few different things but can't quite get it to work.  The closest I have come is to get the style applied to single-word lines using this code that employs a negative lookahead:

       

      ^(\w+)(?!\:)$

       

      But, what I REALLY need is for the (\w+) to instead be something that represents a string of ANY characters (number or letter or hyphen in my case) that does not end with a colon. But if I write something like:

       

      ^.*(?!\:)$

       

      It just applies the style to everything. I need to be able to exclude lines of text that do not end with a colon.

       

      Here is an snippet of text that I am trying to style.  So in the case below, I only want the lines "3-Point Field Goals" and "Team Points"  to have the character style applied. (There is already a different GREP style in the works that will bold the beginning of the other lines through the first colon.)

       

      >>>>

      3-Point Field Goals

      Made: 8 by Meg Bulger vs. Cleveland State, 12/19/05; 8 by Taylor Palmer vs. Youngstown State, 11/11/11

      Attempted: 18 by by Christie Lambert vs. Syracuse, 2/2/97; Christie Lambert vs. Temple, 1/28/95

      Team Points

      Most: 131 vs. Indiana (Pa.), 12/7/82

      Fewest: 30 vs. Seton Hall, 2/2/74

      Most in a Half: 62 vs. Duquesne, 1/14/91

      Fewest in a Half: 13 vs. Oklahoma State, 2/18/15

      >>>>

       

      Help?

        • 1. Re: GREP expression to find a line with no colon
          Chad Chelius Adobe Community Professional

          Maybe this is a better job for a Nested Style and not a GREP style. I created a paragraph style with a nested style that applies bold through 1 colon and applied it to everything. If the line doesn't contain a colon, it applies it to the entire line. If it does have a colon, it only applies bold through the 1st colon in the paragraph. See screen shot below.

           

          Screen Shot 2015-09-10 at 8.35.12 AM.png

          • 2. Re: GREP expression to find a line with no colon
            dooalot Level 1

            Thank you for your reply. Unfortunately I didn't mention that the style being applied to these other lines is not just bold..... it's different in other ways as well (unique case, character color, and leading).... so I really need to be able to be more specific.

            • 3. Re: GREP expression to find a line with no colon
              Chad Chelius Adobe Community Professional

              You can use Nested styles in conjunction with GREP styles. As a matter of fact GREP styles take priority over Nested styles so you should be able to add your GREP expression to the paragraph style definition as well to achieve the desired result.

              • 4. Re: GREP expression to find a line with no colon
                dooalot Level 1

                I understand that. I use GREP in conjunction with Nested styles a lot.  What I'm getting at is, I need someone to help me construct exactly the correct expression that will single out lines of text that do not end in a colon. Application of GREP is not the problem. Discovering the exact expression that will find the pattern I want to single out is my issue. I've been researching it and am unable to find an expression that basically says "find a line of text that does not contain this specific character."  Part of the problem is that there is GREP that people employ in the "real world" and then there is GREP that is specifically applied within InDesign. Some of the "real world" GREP expressions do not translate or work exactly the same within INDD. I have found snippets here and there in "real world" that show me how to match a negative instance of something (for lack of a better term) but I cannot seem to get it just right so that it works in INDD. There are things like applying {0} to a character to tell it to match zero times, and I've also seen reference to using expressions like a -v and "awk" and all sorts of random things. So far I have not been able to write any of these things out in such a way that it will work for me.  Unfortunately, I don't have a ton of time to research all these code-related things when I am under deadline. That's why I was hoping perhaps someone in this forum might be familiar enough with writing GREP that they could help me construct the little snippet of code that I need.

                 

                Sorry for rambling.

                • 5. Re: GREP expression to find a line with no colon
                  Peter Spier Most Valuable Participant (Moderator)

                  You keep saying lines, and you cannot use grep to distinguish the end of a line unless it also has a break of some sort at the end of the line. If you want identify a paragraph that does not end in a colon you could use [^:]$ (that's a negative class that includes everything that is NOT a colon), or (?<!\:)\r (but this one will not find the last paragraph in a story unless it also ends in a return).

                  • 6. Re: GREP expression to find a line with no colon
                    dooalot Level 1

                    Sorry. The problem is that other lines of text within the main paragraph style contain colons (within the text, not at the end of the line/string). Is there a way to "negative match" a string that contains a colon anywhere within it?  Basically if there is a colon anywhere in the string, I need it to ignore that string. If I tell it to find strings that don't end in a colon, it will actually find everything.

                    • 7. Re: GREP expression to find a line with no colon
                      John Mensinger Adobe Community Professional & MVP

                      Well, what Peter was trying to explain in post #5 is that GREP can't "see" where a "line" (or what you're now calling a 'string') begins or ends, and so of course it can't guess how to qualify whether there is a colon included within. There has to be something to mark the beginning and the end of a found "string."

                      • 8. Re: GREP expression to find a line with no colon
                        dooalot Level 1

                        I actually DO understand that. What I'm looking for is how to "negative match" (for lack of a better term) a colon. Can everyone please extend me a little grace for the fact that I don't know all the exact, correct lingo?

                         

                        Let me start again. here is an example of text I need to style (in reality, I have many pages of similar text). The same paragraph style is applied to ALL of it. I want to use GREP to apply a specific, unique character style that I have set up to ONLY the lines that do not contain a colon.

                         

                        >>>>

                        3-Point Field Goals

                        Made: 8 by Meg Bulger vs. Cleveland State, 12/19/05; 8 by Taylor Palmer vs. Youngstown State, 11/11/11

                        Attempted: 18 by by Christie Lambert vs. Syracuse, 2/2/97; Christie Lambert vs. Temple, 1/28/95

                        Team Points

                        Most: 131 vs. Indiana (Pa.), 12/7/82

                        Fewest: 30 vs. Seton Hall, 2/2/74

                        Most in a Half: 62 vs. Duquesne, 1/14/91

                        Fewest in a Half: 13 vs. Oklahoma State, 2/18/15

                        >>>>

                        • 9. Re: GREP expression to find a line with no colon
                          Peter Spier Most Valuable Participant (Moderator)

                          So, if I understand what you are saying now, you want to find only paragraphs that contain no colons at all, not that don't end with a colon. That would be ^[^:]+$ which requires every character from the beginning to end of the paragraph to be a member of the not a colon class. In your sample above it would match only 3-point Field Goals and Team Points.

                          • 10. Re: GREP expression to find a line with no colon
                            Peter Spier Most Valuable Participant (Moderator)

                            By the way, rather than use this as a GREP style, I'd use Find/Change to find those paragraphs and assign a paragraph style with the correct formatting.

                            • 11. Re: GREP expression to find a line with no colon
                              dooalot Level 1

                              Peter... yes, you understand what I am saying, thank you and I apologize for not being crystal clear before. However, the expression you suggested does not work for some reason (I tested it). It would work for the find/change just fine... I just wanted to do it the other way, in this instance. I guess I'm going to have to apply a separate paragraph style instead of achieving it through a single, more complex style that is applied to everything.

                               

                              Thanks for your help.

                              • 12. Re: GREP expression to find a line with no colon
                                Peter Spier Most Valuable Participant (Moderator)

                                It works here as a GREP style in CS6....

                                 

                                But applying a character style to an entire paragraph is just poor typography. Character styles should be used only to modify isolated text within a larger paragraph.

                                • 13. Re: GREP expression to find a line with no colon
                                  Chad Chelius Adobe Community Professional

                                  I couldn't agree more Peter!

                                  • 14. Re: GREP expression to find a line with no colon
                                    pixxxel schubser Level 5

                                    dooalot schrieb:

                                     

                                    … using GREP… to lines of text that DO NOT contain a colon …

                                    Try this one:

                                    ^[^:\n\r]+$

                                     

                                    or this one as GREP style:

                                    ^[^:]+$

                                     

                                    Have fun

                                     

                                    • 15. Re: GREP expression to find a line with no colon
                                      Obi-wan Kenobi Adobe Community Professional

                                      Hi Pixxel,

                                       

                                      ^[^:]+(?=$)

                                       

                                      works for me as grep style or grep find/replace [ID CC 2014].

                                       

                                       

                                      • 16. Re: GREP expression to find a line with no colon
                                        Peter Spier Most Valuable Participant (Moderator)

                                        pixxxel schubser wrote:

                                         

                                        dooalot schrieb:

                                         

                                        … using GREP… to lines of text that DO NOT contain a colon …

                                        Try this one:

                                        ^[^:\n\r]+$

                                         

                                        or this one as GREP style:

                                        ^[^:]+$

                                         

                                        Have fun

                                         

                                        Your second expression is the same as the one I posted above, so I know it works, and I tried the first one and it works too, but for the life of me I don't understand why. How can you include not a return and still match to the end of a paragraph?

                                        • 17. Re: GREP expression to find a line with no colon
                                          Obi-wan Kenobi Adobe Community Professional

                                          Peter,

                                           

                                          It doesn't work for me!

                                          Capture d’écran 2015-09-10 à 21.30.47.png