6 Replies Latest reply on Sep 29, 2011 12:58 PM by Peter Spier

    GREP styles vs style sheets


      I've got a lull at work and decided to work on my list and start to learn GREP so that I can use GREP styles.


      The first one is a simple one:  [[A-Z][A-Z]\S+?] This finds anything inside the brackets that starts with two capital letters. I know it works because I can find "[MT2]" in Find/Change.


      OK, so I try it in some ID cs5 text with my first GREP style. It's failing the vast majority of the time. So I try lots of different things to see if I can find a pattern of what works and what doesn't. I've tried just the local formatting of a lone 'graf. I've tried making character and 'graf style sheets that incorporate a GREP style with the new character style, say "change type color to green".


      I've looked through the forums and don't see others with my problem so it must be something about me or my document. I've used other documents to eliminate that variable. I've gone through the tutorials and David Blatner's stuff and don't see anything I'm doing differently.


      When I format some text with a character and 'graf style sheet, it fails. BUT when I change the character style sheet of the source text to "[None]" it works. I've tried starting with text that is '[None]' and a 'graf style sheet of Normal, it works.


      But starting with text styled with '[None]' character and a formal 'graf style sheet with a GREP Style, it fails. But when I change the 'graf style sheet to ]'Basic Paragraph]' it works.


      I'm trying to find a pattern here, so to speak, and the only thing that has a chance to succeed is setting the character style sheet to 'None.' I just don't see than anyone who uses GREP styles has any problems like I do.


      What do you reckon I'm overlooking? I've spent today trying to find what works and doesn't. As it is, I can't recommend this to my co-workers.

        • 1. Re: GREP styles vs style sheets
          Peter Spier Most Valuable Participant (Moderator)

          Are you trying to find the brackts as well as text inside them? If so, you need to "escape" them becasue brackest are a special character in GREP. Your expression should be


          • 2. Re: GREP styles vs style sheets
            sam452 Level 1

            Yes, I am and in the few times that it does seem to work it does get the brackets as well. Even if it didn't, I'd be happy to get consistency about when the entire operation works and doesn't. Right now, I don't have that basic thing figured out yet.


            Thanks for responding.

            • 3. Re: GREP styles vs style sheets
              sam452 Level 1

              To be certain, escaping the open/close bracket yields no different results than previous tests without escaping.

              • 4. Re: GREP styles vs style sheets
                Peter Spier Most Valuable Participant (Moderator)

                First off, I'm not sure what's failing in your expression, nor am I sure why it is picking up the brackets without escaping. One of the experts in GREP might know, but from what I can tell, it shouldn't since the brackets are used to define a class. Your expression will fail, for sure, if there is any white space at all inside the brackets, however, so that might be part of the problem.


                If what's failing is that the GREP style is not changing text to which another character style is applied, I think that's expected behaior. Character styles override Paragraph styles, and the GREP style is part of the paragraph style. You should expect the GREP style to control only those attributes that are not controlled by the second applied character style, so if the GREP style says make the text bold and red, and the applied character style says  make the text green and 20 pts, you shoud expect to see bold 20pt green text.



                The following expression may be a bit cleaner and will pick up anything (shortest match) including white space that is surrounded by brackets and starts with two uppercase letters:



                • 5. Re: GREP styles vs style sheets
                  sam452 Level 1

                  Thank you for replying. The supplied tightened pattern is appreciated as I am happy to learn more. My pattern still works fine, but the discussion of the character/paragraph style is on the right track.


                  It's helpful to understand that character styles are overrides as you say. So, testing this I set a test 'graf to "[None]" and made a new 'graf style with character traits as desired. Then I forced the test 'graf to this style. Then I applied your, and mine above for laughs, pattern in a GREP style within the 'graf style. That works.


                  I guess best practice is not to apply any character style to copy, but rather let the paragraph style define what the character style should control. If I have to apply a character style, it would seem to me that I may have to determine which would override if I'm going to apply it to a string that is covered by the GREP style within the ruling 'graf style. That is to say, would a character style manually applied after the fact to a string being ruled by a GREP style? I think I'm starting to see how the style sheets are interacting. Any other insight in how they play would be appreciated, sam

                  • 6. Re: GREP styles vs style sheets
                    Peter Spier Most Valuable Participant (Moderator)

                    Rule of thumb for applying styles is basic formats for the entire paragraph should be defined in the paragraph style. If some selected bit of text needs to be formatted differnently, then you apply a character style (or, if you must, a local formatting override). With Nested Styles and GREP styles, ID has very powerful tools for applying character styles to selected text WITHIN the confines of the paragraph style definition. Most programs don't have that capability.


                    Should you apply the character syle as a nested or GREP style, or perhaps through Find/Change, or just by manually selecting text and applying the style? The answer to that will depend on a few variables. Should the particular string ALWAYS have a particular set of attributes, no matter what? Find/Change or local selection is the way to go. Character styles applied that way will survive even if the underlying paragraph style is changed to match the character style, then changed again. If the style should be applied to a string in a particular position in a paragraph, even if that position might move around a bit, a nested style is probably the way to go. If you want to make changes to text that matches a particular pattern, wherever it falls, when the surrounding text is a particular style, a GREP style is the answer.


                    GREP styles are very powerful, but they also use far more in terms of resources than applying a character style using other methods. I've seen reoprts of ID getting bogged down by too many GREP styles.