Skip to main content
Participant
May 9, 2025
Question

GREP for bolding all numbers (including commas, decimals, and percent signs) EXCEPT years

  • May 9, 2025
  • 1 reply
  • 936 views

Hello! I would like to creat a GREP that bolds all numbers (including commas, decimals, and percent signs), but excludes a number that follows the name of a month. I also need one to italicize the phrase "The Movement." Example sentence below:

 

In August 2024, we wrapped a year of strategic initiatives. Our survey found that 100% of respondents agree or strongly agree that The Movement was a successful film rollout campaign. 

 

I have two character styles and two GREP created:

  • bold numbers applied to (\d{1,3}(?:,\d{3})*(?:\.\d+)?%?|\d+(?:\.\d+)?%?
  • italicized movement applied to \b(The Movement)\b

 

when I add a third character style and try different GREP to exclude the August 2024 from bolding, 100% is no longer bolded. any ideas?

1 reply

Joel Cherney
Community Expert
Community Expert
May 9, 2025

I'm having a hard time parsing your "bold numbers" regex, to be honest. Shouldn't it start with (\d{1,3})? Also it's hard to know what's going wrong when you don't tell us your query that is removing boldface from 100%. 

 

I would suggest that you break your regex into a few smaller bites:

 

1) Apply Character Style "bold numbers" to all numbers in the document via Find/Change with a search for: \d+

2) Apply Character Style "bold numbers" to any of your specified punctuation preceded by a digit: (?<=\d)[,|\.|%]

3) Apply Character Style "[None]" to any four digits preceded by the name of a month, including the comma if present: (?<=[January\s|February\s|March\s|etc])\d{4},?

 

I'm assuming that there aren't any digits, in longhand-month-and-year dates or otherwise, that aren't already marked with a character style.

m1b
Community Expert
Community Expert
May 9, 2025

Hi @Joel Cherney this is a very good approach and logically set out.

 

For my learning I went to apply it and found one small issue: Applying Character Style "[None]" didn't override a previously-applied-grep character style, so I had to set it to a character style which simply matched the main text. Is this your experience? I've attached my demo document, which seems to work the way the OP asks and follows your advice except I combined your steps 1 and 2 which is probably not as good for readability and maintainability.

- Mark

Joel Cherney
Community Expert
Community Expert
May 10, 2025

You know, Mark, I did write a post all about GREP Styles. I have also had collision issues like the ones you describe. I actually started going off on a tangent, longing for cascading styles in InDesign. Because yes, I have noticed that a manually applied style can't cancel a style applied via GREP Style. I've dug myself some fairly deep holes in the recent past (client's file had six GREP Styles applied for bold and such, the Arabic needed an additional eighteen GREP Styles to account for all the possible permutations). After enough of those experiences, I think hard when I'm deciding between using GREP Styles and simply having a list of F/C queries that I run from the Find/Change dialog, or from a script. 

 

Anyhow, after going off the rails pining for CSS with a graphical property-inheritance browser in InDesign, I went and read the original post. GREP Styles are never mentioned. There are character styles applied by GREP, but no GREP Styles. So I rewrote the post to be a series of normal Find/Change queries. The only reason I broke the query out into individual steps was to make it easier for a human brain to parse - I likely  would have never spotted the missing close parenthesis myself. I dropped the OP's query into someone's regex-parser tool, because my brain simply wouldn't parse the original query.