Search code examples
grepstylesadobe-indesign

GREP: how to match positive or negative digit?


I would to apply a text style on a percentage (%) number according to is polarity. Like, if I get a -21% so I would Indesign apply the style1, if it's 21%, ID must apply another style.

This is my starting point to match content:

\.^-\d+\K%  for negative digit

^+\+\d+\K% for positive

If someone can help me, it's my first time using GREP style in ID.

Thanks


Solution

  • For positive values use

    ^[+]?[0-9]+%$
    

    For negative values, use

    ^-[0-9]+%$
    

    Details

    • ^ - start of string
    • [+]? - an optional + char
    • - - a - char
    • [0-9]+ - 1 or more digits
    • % - a % symbol
    • $ - end of string.