6 Replies Latest reply on Apr 22, 2011 11:42 AM by Tom Usrey

    CS5 - Grep style problems

    Tom Usrey Level 3

      Where I work the treatment of the type is to reduce the size of all-caps, a string of numbers, or a combination of the two. For years they've been doing it by setting up a Character Style for each Paragraph Style (e.g., "Body smaller" for "Body), and then also alternate Character Styles if the text already has a Character Style applied to it ("Body Red Italic smaller" for "Body Red Italic"). You can imagine this quickly becomes a lot of styles.

       

      So I thought with CS5 Grep styles I could set this up in the Paragraph Styles. I want the Grep style to apply a Character Style that is nothing but a Horizontal and Vertical scale of 95%.

       

      The types of things I'm wanting Grep to find are below. But I'm only wanting to apply the style to the letters and numbers and not the punctuation.

       

      AAA
      B23
      33,333
      4,444,444
      U.S.A.
      (ABC-1)

       

      I went at writing this a piece at time, so it is not very elegant. Here's what I have:

       

      \d{2,}|\u{2,}|\u+\d+|\d+\u+|\d+[[:punct:]]\d+|\u+[[:punct:]]\u+|\u+[[:punct:]]\d+|\d+[[:pu nct:]]\u+

       

      This does a pretty good job, with a couple of problems.

       

      1) It is "catching" (applying the character style) to the first punctuation if there is a single character before it (e.g. the first piece of punctuation in 4,444,444 and U.S.A.)
      2) It is not always "catching" instances where there are more than three sets of numbers/caps in an item (e.g. U.S.A., it doesn't style the "A"). I know Grep is probably just doing what I'm telling it to do, but I can't see how to fix it.

       

      I would appreciate any help anyone could give me.

       

      Thanks.

       

      Tom

        • 1. Re: CS5 - Grep style problems
          Peter Kahrel Adobe Community Professional & MVP

          You can't do all this in one GREP style. The one you came up with is already difficult to read, so you can imagine what happens to its readability by the time you get it to work. Apart from that I don't think it's possible to do what you want in one expression.

           

          So you really need to split up your task into several chunks, all of which you can then add to the same paragraph style. Your expressions may be more efficient, but they're much eaier to understand and maintain. Here goes.

           

          The easy ones are AAA, B23, and (ABC-1), all of which are captured by this expression:

           

          \(?\u[-\u\d]+\)?

           

          U.S.A. is more tricky, and it needs to be split in two itself. The first part captures series capital+period, but not the last one:

           

          \u(?=\.\u)

           

          Capturing the last capital+period is interesting in that it requires a negative lookahead embedded in a positive lookahead, which I wouldn't have thought was possible, but it works:

           

          (?<=\.)\u(?=\.(?!\u))

           

          For the numbers you's do something similar.

           

          Peter

          1 person found this helpful
          • 2. Re: CS5 - Grep style problems
            Tom Usrey Level 3

            Peter,

             

            Thanks for your input. I realize your suggestion about splitting it up is the way to go. And your handling of the "U.S.A." sample is right on.

             

            But I see that I need to do some more playing around to see if I'm going to be able to get this to work. For example, your expression to catch one of the "easy ones" -- (ABC-1) -- also catches all the punctuation, and I didn't want to catch any of the punctuation. And in the sample "4,444,444" mine was catching the first punctuation, but yours instead isn't catching the first character. So I'm going to continue working on this and will come back later if I get something that works.

             

            Hopefully your help has put me on the right track.

             

            Tom

            • 3. Re: CS5 - Grep style problems
              Marc Autret Level 4

              Hi Tom,

               

              Just a stupid question. What is the issue in using a rule like:

               

              [\u\d](?![\l'])

               

              ?

               

              @+

              Marc

              1 person found this helpful
              • 4. Re: CS5 - Grep style problems
                Peter Kahrel Adobe Community Professional & MVP

                >  I didn't want to catch any of the punctuation

                 

                Then just leave out the punctuation: \u[-\u\d]+

                 

                The numbers can probably be captured by this one:

                 

                \d?\d?\d(,\d\d\d)+

                 

                i.e.batches of comma+three digits preceded by at least one but up to three digits.That's the pattern that your examples suggest.

                 

                Peter

                • 5. Re: CS5 - Grep style problems
                  Tom Usrey Level 3

                  Marc,

                   

                  Yours also catches the single caps or digits that stand by themselves.

                   

                  For example, in the sentence -- A train of 3 cars -- we don't watch to catch the "A" or the "3".

                   

                  Other than that, yours seems to work the way we wanted.

                  • 6. Re: CS5 - Grep style problems
                    Tom Usrey Level 3

                    Peter and Marc,

                     

                    Thanks to both of you for your insight on my problem. I've taken a little of both of your answers and think I'll be able to work them into a solution for our needs.

                     

                    I've awarded each of you a "Helpful Answer".

                     

                    And Peter, just wanted to let you know that your O'Reilly GREP digital book has been a great help me in beginning to learn GREP.

                     

                    Tom