Using GREP to select a number range
Learn / Forums / General InDesign Topics / Using GREP to select a number range
Tagged: GREP
- This topic has 5 replies, 3 voices, and was last updated 8 years, 11 months ago by Masood Ahmad.
-
AuthorPosts
-
-
April 27, 2015 at 2:13 pm #75009JahrodMember
I thought this would be simple (and probably it is) but after searching the web for no less than an hour, I can not figure out how to get GREP to select a number range. What I would like GREP to do is select all numbers from 1 to 49 so I can colour them with a certain colour using a character style built into my paragraph style. Then I also want to colour numbers 50 to 59 with another character style. Does anybody know how I might be able to do this?
-
April 27, 2015 at 3:49 pm #75013Wosven SMember
Perhaps there’s a more elegant solution, but an easy way is :
First, you can color all numbers :
GREP style color 1-49
\d
Second, you color from 50 to 59 :
GREP style color 50-59
5\d
If needed for 60+ :
GREP style color 60+
[6-9]\d|[\d]{3,}
-
April 27, 2015 at 11:13 pm #75020JahrodMember
@Wosven, this is absolutely PERFECT – thank you! I actually need a code for 60+, so thanks for dropping that one in too :)
Out of curiosity, how exactly does that last code work? Possible for you to break it down on what each part does?
Many thanks
-
April 28, 2015 at 1:30 am #75022Masood AhmadParticipant
This GREP code is a combination of two codes with an IF condition using a Pipe sign (|)
[6-9]\d
means any digit from 6 to 9 followed by any digit
= This code will select/search all the numbers starting with 6 to 9|
pipe sign means OR (a kind of if condition)The second part
[\d]{3,}
will select all the digits with a minimum of 3 digitsIt means that this code will select all the numbers…
Instead if you need to select the numbers from 60 to 99 then you can tweak the @Wosven code to:
[6-9]\d
but keep this in mind that this code will also search/select the numbers in between bigger numbers, therefore, you have to look for the numbers that are not preceded by a digit:(?<=[\D])[1-4]\d
(?<=[\D])5\d
(?<=[\D])[6-9]\d
Similarly if you want to restrict your search to a two-three digit search string then you can add an additional code, like: {1} or {2} or {3}
(?<=[\D])[1-4]\d{2}
(?<=[\D])5\d{2}
(?<=[\D])[6-9]\d{1}
Hope this will help
-
April 28, 2015 at 4:53 am #75026JahrodMember
Masood Ahmad, amazing – thank you so much for the thorough breakdown! Saving me so much time already :)
-
April 28, 2015 at 5:18 am #75027Masood AhmadParticipant
I’m glad, I could help… :)
-
-
AuthorPosts
- You must be logged in to reply to this topic.