Skip to main content
Inspiring
September 27, 2017
Answered

Grep to find a range of numbers

  • September 27, 2017
  • 1 reply
  • 3540 views

Hi,

Can anyone help with a grep query that finds specific ranges of numbers?

I'm trying to find/replace specific ranges so that any number found within that range has its paragraph style changed.

There are four ranges and I've worked out the last two, but am struggling with the first two without affecting higher numbers.

1-45 = ?

46-90 = ?

91-135 =

9[1-9]|1[0-2]\d|13[0-5]

136-180 =

13[6-9]|1[4-9]\d

Anyone know how?

    This topic has been closed for replies.
    Correct answer Obi-wan Kenobi

    \b([1-9]|[1-3][0-9]|4[0-5])\b

    \b(4[6-9]|[5-8][0-9]|90)\b

    \b(9[1-9]|1[0-2][0-9]|13[0-5])\b

    \b(13[6-9]|1[4-7][0-9]|180)\b

    (^/)

    1 reply

    amaarora
    Community Manager
    Community Manager
    September 27, 2017

    Hi,

    Both of the needed greps look fairly easy to construct.

    I would recommend you read this article https://indesignsecrets.com/topic/using-grep-to-select-a-number-range  and still if you face any difficulty do let us know.

    -Aman

    JustyRAuthor
    Inspiring
    September 27, 2017

    Hi, I've wlready been through that one. I can get round the problem by doing find/change grep queries one after the other. So if the first changes every number, the next will change from where I need it to, then the next and so on.

    Thought there would be something more specific to pin down exact ranges.

    Obi-wan Kenobi
    Obi-wan KenobiCorrect answer
    Legend
    September 27, 2017

    \b([1-9]|[1-3][0-9]|4[0-5])\b

    \b(4[6-9]|[5-8][0-9]|90)\b

    \b(9[1-9]|1[0-2][0-9]|13[0-5])\b

    \b(13[6-9]|1[4-7][0-9]|180)\b

    (^/)