7 Replies Latest reply on Dec 5, 2011 8:54 AM by m_maclean

    GREP help - string of numbers, fractions, decimals formatting change

    m_maclean

      I haven't used GREP before so I apologize if this is really basic stuff here.

       

      I write technical documents that list ~12 measurements in imperial and metric with the following format

       

      32 ½ (34, 36 ½, 38, 40 ½, 41 ½, 44, 45 ½, 48, 52, 55 ½, 59 ½)” / 82.5 (86.5, 92.5, 96.5, 103, 105.5, 112, 115.5, 122, 132, 141, 151) cm

       

      There are dozens of these strings of numbers throughout the document as well as variants like this where hyphens indicate that the instructions don't apply to particular sizes:

       

      32 ½ (-, -, 38, 40 ½, -, -, 45 ½, 48, -, 55 ½, -)" / 82.5 (-, -, 96.5, 103, -, -, 115.5, 122, -, 141, -) cm

       

      What I want is to make the middle 4 values of both the metric and imperial, bold. What I thought I'd do is find the whole string, make it bold, then find the first 4 and make them plain text, the middle 8 and make them plain text and the last 4 and make them plain text.

       

      At present, I can't even figure out how to find the full string. I can find a digit or two digits but then the space and fraction doesn't get found. The metric values range from single to triple digits plus a possible decimal. The imperial can have single or double digits plus an optional fraction. The location of the parenthesis, inch marks, and "cm" is always consistent. If I can understand how to find the string, I think I can muddle through the rest. Can someone help me out?

       

      Thanks in advance.

        • 1. Re: GREP help - string of numbers, fractions, decimals formatting change
          [Jongware] Most Valuable Participant

          Don't fret, this is a tricky. Let me think-and-try-while-I-type.

           

          Start with creating a suitable Highlight Me character style (an underline with thickness 12 pt, vertical offset -3 pt, color Gaudy Bright Pink). That way -- with Preview enabled, of course -- you can clearly see the changes.

           

          Okay, one step at a time:

          1. The default GREP style "\d+" works.

          2. To make it accept periods and/or fractions as well, change it to "[\d ½.]+" (including the space character).

          3. To make it accept either a value like this or a single hyphen, change it to "-|[\d ½.]+"

          4. To make it accept a comma-separate range of these, change to "(-|[\d½ .]+)(, (-|[\d½ .]+))*"

          We're getting there. It's impossible to format "the four right after four others at the start" because 'four at the start' can be of variable length, so we have to do the trick you already mention: format up to the required number as bold, then remove bold from the first four.

          Here we go:

          5. This will format 1 single, then 7 repeated items (because of the comma) right after an opening parenthesis:

          "(?<=\)(-|[\d½ .]+)(, (-|[\d½ .]+)){7}"

          Apply Bold to this.

          6. This will format 1 single, then 3 repeated items, also right after the opening parenthesis:

          "(?<=\)(-|[\d½ .]+)(, (-|[\d½ .]+)){3}"

          Apply Not-Bold to this.

           

          We're almost there, aren't we? Look at that: (I added underlining is for clarity)

           

          metrics.PNG

           

          Last thing to get rid of is the bold comma right before your bold run. Theoretically I could adjust the not-bold GREP expression to explicitly exclude it, but in this case it's easiest to just tack it at the end, resulting in

          "(?<=\)(-|[\d½ .]+)(, (-|[\d½ .]+)){3}, " (note the space at the end).

          If you don't like the comma's inbetween to be bold, you can also apply your not-bold char style and this simple GREP:

          ", "

           

          -- just "comma-space".

           

          Message was edited by: [Jongware] Okay, so now I'm getting another new sort of Jive Horror. (FYI, "Jive" is the web-based editor that everyone is obliged to use. It's also a slang term, meaning, uh, well "büllshıt", which is strangely appropriate.) I see loads of #### right after some of the GREP expressions but cannot edit them out. If you see them as well: ignore them, please. What a bunch of jive.

          1 person found this helpful
          • 2. Re: GREP help - string of numbers, fractions, decimals formatting change
            m_maclean Level 1

            Wow, thank you so much. One bone headed thing I didn't mention is that the imperial numbers can be any quarter inch fraction (1/2, 1/4 or 3/4) is there a grep metacharacter that will capture any of the three? It's a glyph, I think so maybe [[=a=]]?

             

            hmm, that definitely isn't it that only finds variation on a particular letter. :\

            • 3. Re: GREP help - string of numbers, fractions, decimals formatting change
              [Jongware] Most Valuable Participant

              Yup, [[=a=]] is a convenient shortcut but it's not meant to find your quarters.

               

              Just copy-and-paste those other fractions out of your document in my expression(s), right after each ½. That will include them in the character set that already finds digits, halve-fractions, spaces, and periods.

              1 person found this helpful
              • 5. Re: GREP help - string of numbers, fractions, decimals formatting change
                m_maclean Level 1

                I just wanted to add a note that I just tried this and it worked like a charm, I ended up using these final GREP searches

                 

                Find the full string and add bold character style

                (-|[\d½ ¼ ¾ th rd st.]+)(, (-|[\d½ ¼ ¾ th rd st.]+))* \((-|[\d½ ¼ ¾ th rd st.]+)(, (-|[\d½ ¼ ¾ th rd st.]+))*\)

                 

                Find the first 4 and remove character style

                ((-|[\d½ ¼ ¾ th rd st.]+)(, (-|[\d½ ¼ ¾ th rd st.]+))* \()(-|[\d½ ¼ ¾ th rd st.]+)(, (-|[\d½ ¼ ¾ th rd st.]+)){2},

                 

                Find the last 4 and remove character style

                (-|[\d½ ¼ ¾ th rd st.]+)(, (-|[\d½ ¼ ¾ th rd st.]+)){3}\)

                 

                 

                I definitely wouldn't have figured that out on my own. I can't thank you enough.

                • 6. Re: GREP help - string of numbers, fractions, decimals formatting change
                  Laubender Adobe Community Professional & MVP

                  And the best of it:

                  if you are in InDesign CS4 or up, you can execute all three GREPS automatically one after another inside one paragraph style using GREP styles together with two character styles…

                   

                  Uwe

                  • 7. Re: GREP help - string of numbers, fractions, decimals formatting change
                    m_maclean Level 1

                    I'm in CS5, I will have to give that a try because that's downright brilliant. I actually have to apply different character styles depending on the paragraph style because some paragraph styles are italic and some are plain, so the former needs bold italic and the latter needs simple bold.

                     

                    ETA: That worked really well, I had to make a plain text character style (versus appling "none") for it to work but work it did. This is amazing.

                    https://img.skitch.com/20111205-ck4tt1d743fju9nbtdfmeh8d7f.jpg