Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP: changing the style of percentages within body copy

Return to Member Forum

  • Author
    Posts
    • #14338730
      Geoffrey West
      Participant

      I’m sure a GREP sorcerer knows this in his/her sleep, but I’m trying to change the color/styling of percentages (30%, 47%, etc.) within long blocks of copy. What’s the GREP command to apply that?

    • #14338745
      David Blatner
      Keymaster

      You could use a GREP Style, with an expression like \d+?%
      More here:

      5 Cool Things You Can Do with GREP Styles

      • #14338767
        Geoffrey West
        Participant

        Thanks, David.

        I actually tried this and it worked out:

        \w{2}\%

        I think that will suffice for my current application, but now that I think about it… any number that’s more than 3 digits won’t work (i.e. 100%).

        *switches to InDesign to test*

        Yep… ok. You win! Yours is better! Thanks again!

    • #14338771
      Geoffrey West
      Participant

      OK, hold up… new roadblock!

      How do I modify the GREP style to account for partial percentages, such as 4.1% or 39.5%?

      Any ideas?

    • #14338776
      David Blatner
      Keymaster

      Ah yes! With GREP you have to be extremely precise. The code I gave you only looks for digits followed by a percent symbol. If you want to look for numbers or dots, you’d have to use [\d\.]+?%

      The \d means “number”, the \. means a dot or period. The square brackets mean “or”

      • #14338778
        Geoffrey West
        Participant

        Thanks, David!

        One last question: What is the benefit or significance of adding the ? within the GREP expression? I’ve seen that randomly when searching for other GREP solutions. I’ve seen it referred to as “lazy,” but what is actually happening within the GREP expression when the question mark is added?

    • #14338779
      David Blatner
      Keymaster

      Actually, in this case it’s not needed. I do it out of habit.
      Here’s where it comes in handy… given the sentence:
      There are 1 (one) or 2 (two) options
      And if you use grep to search for \(.+\) (which means “find everything between two parentheses) then it will find “(one) or 2 (two)” — that is, all the way from the first open paren to the last close paren.
      But if you add the ? after the +, then it would just find “(one)” and then it will find “(two)”
      So the ? sort of means “find the shortest amount of text that works.

    • #14338784

      [\d.]+%

Viewing 5 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads