11 Replies Latest reply: Aug 1, 2012 4:59 AM by Peter Spier RSS

    Apply grep style only once

    RobertKyle Community Member

      I can't get my brain around what is probably a very simple problem: I want a paragraph style that applies boldfacing to any character up to an including the first colon in a paragraph. If I used  a nested style "through 1 :" the whole graf is bold if there is no colon. So that's out.

       

      A grep style ".+: " seems to work in most cases, but if there's a second colon, the boldfacing is extended to that point. What I think I want is a grep style that works "zero or 1 times" but I cannot figure out how to use the ? to make that happen.

        • 1. Re: Apply grep style only once
          Laubender MVP

          @Robert – try this one:

           

          ^.+?:+?
          

           

          Uwe

          • 2. Re: Apply grep style only once
            RobertKyle Community Member

            Perfect! Thank you. But what does it say? I get "beginning of paragraph, any number of characters" but after that it's murky to me

            • 3. Re: Apply grep style only once
              Laubender MVP

              @Robert – I did a little trial and error and we can reduce the expression to:

               

              ^.+?:
              

               

              It's the "not greedy" version of:

               

              ^.+
              

               

              followed by the colon.

               

              My first attempt added a not needed part I did not delete after experimenting.

               

              Uwe

              • 4. Re: Apply grep style only once
                RobertKyle Community Member

                Thanks again. So now I'm wondering how to limit the grep to the first line? I see the modifiers for single line on and multi line off, but I'm obvously not putting them in the right position

                • 5. Re: Apply grep style only once
                  [Jongware] MVP

                  A-ha. Now that is not possible with GREP styles -- they are part of a paragraph style, and strictly limited to text inside each paragraph. No peeking out of it either way. Single-line and multi-line modifiers do not work, and neither does fiddling with \r anywhere inside a GREP style.

                   

                  You have to create another paragraph style containing this GREP only, and apply it to your first paragraph.

                  • 6. Re: Apply grep style only once
                    Laubender MVP

                    @Jongware – I think Robert wants to limit the GREP style to the first line of a paragraph.

                    But unfortunately GREP in InDesign does not know about line endings.

                     

                    In scripting we could do something like what he wants, but comes with some obstacles, because the GREP will apply a character style, that will probably change the line ending. A very dynamic situation…

                     

                    Example 1

                     

                    Basic situation:

                     

                    This is my text here comes the colon: and

                    here another one: that Robert don't like

                    to take into account using the GREP style.

                     

                    Formatted after  the GREP style is applied:

                     

                    This is my text here comes the colon: and

                    here another one: that Robert don't like

                    to take into account using the GREP style.

                     

                    As I understand it, in case that the first colon will leave line one, only the first line should be formatted like this:

                    (Case 1)

                     

                    This is my text here comes the first

                    colon: and here another one: that

                    Robert don't like to take into account

                    using the GREP style.

                     

                    Or should it be, that the style should only be applied, if it's in the first line?
                    (Case 2):

                     

                    This is my text here comes the first

                    colon: and here another one: that

                    Robert don't like to take into account

                    using the GREP style.

                     

                    But what, if the colon in the basic case is at the end of line 1 and will be shifted to line 2 after formatting?

                    What should happen then?

                     

                    That is simply not possible to format automatically (dynamically) using GREP styles in InDesign.

                     

                    Uwe

                    • 7. Re: Apply grep style only once
                      Peter Spier ACP/MVPs

                      Uwe, I don't see that at all in the original post. He seemed quite clear to me that he wanted to apply the style up the first colon, no matter where, and not beyond, and that the style should only be applied IF there is a colon, ruling out a regular nested style. The only reference I see to anything like the first line is the beginning of paragraph mark.

                      • 8. Re: Apply grep style only once
                        Laubender MVP

                        @Peter – I assumed this because of:

                         

                        So now I'm wondering how to limit the grep to the first line

                         

                        in #4.

                         

                        I could be totally wrong…

                         

                        Uwe

                        • 9. Re: Apply grep style only once
                          Peter Spier ACP/MVPs

                          Ah yes, missed that. It is ambiguous, isn't it?

                          • 10. Re: Apply grep style only once
                            Laubender MVP

                            Yes.

                             

                            If a "Nested Line Style" could overwrite a "GREP Style", we could manage that, but "unfortunately" that isn't…

                             

                            Not working example:

                             

                            GREP Style:

                            Apply Style: "BoldFont_CharacterStyle"

                            To Text: ^.+?:

                             

                            Nested Line Styles:

                            [None] for 1 lines

                            "RegularFont_CharacterStyle" for 999 lines

                             

                            Uwe

                            • 11. Re: Apply grep style only once
                              Peter Spier ACP/MVPs

                              suppose you approach it the other way. Apply the line style to the first line and then apply a GREP style to UNdo it after the first colon with a lookbehind? Not quite sure how to make that work so the line style is removed if there is no colon... Perhaps a second GREP style that looks for the string at the beginning and checks for a colon, but I'm not sure how to prevent that from being applied if the colon is found.