Skip to main content
Participant
June 6, 2019
Answered

Grep Styles for an Entire Paragraph

  • June 6, 2019
  • 3 replies
  • 1811 views

Hello all,

I'm very new to the GREP Styles (just discovered it yesterday) and I'm wondering if there's a GREP Style to be able to detect a certain word in a paragraph and change the color of the entire paragraph based on that word?

Background: I'm working on a card project that has color-coded text based on the subject matter and there's a total of about 48 cards ranging with 8 different subject matters. I'm just trying to see if there's a way to color code these paragraphs on each card without needing to manually do it.

In this case, I want the entire paragraph 'We're investing...communities' to be the tinted orange.

I'm hoping there's a better solution (or script!) than me manually selecting the text on all these cards vs me just selecting keywords.

This topic has been closed for replies.
Correct answer Jongware

Hi Vinny:

I can see your point. In the spirit of continuing my GREP education, how would you write this differently, given the one example from the OP?

~Barb


That would be something like:

(?i).*\b(safe)\b.*

where

(?i) switches GREP to Case Insensitive mode

.* (instead of .+) so there may be zero or more characters before the word in question

\b <word> \b forces word breaks before and after -- i.e., this is one "entire word"

( <word> ) -- parenthesis around the word to look for -- is so you can use a single GREP for multiple words, using the OR | bar to separate them (like|this)

.. and after that, a word break to end the word and zero or more any-characters all the way up to the end.

Ha, I see Vinny indeed came up with this exact same expression!

3 replies

Barb Binder
Community Expert
Community Expert
June 6, 2019

Hi Kburns​:

Please give Vinny's expression a try and let us know if it works for you. If so, one of us can mark it as the correct answer.

~Barb

~Barb at Rocky Mountain Training
Participant
June 6, 2019

Thanks all! I will try them both and see what works best. Now I'm realizing there might be multiple words for some paragraphs I need to callout so would I just use (?i).*\b(safe) | (communities)\b.* or maybe .+safe | communities.+ ?

vinny38
Legend
June 6, 2019

(?i).*\b(safe|communities)\b.*

as per Jongware good advice

Frans v.d. Geest
Community Expert
Community Expert
June 6, 2019

Create  Paragraph Styles, search for a word and in Replace choose the correct Paragraph style.

Barb Binder
Community Expert
Community Expert
June 6, 2019

Hi Kburns:

I'm still learning GREP so perhaps someone else has a more elegant solution but this works:

.+safe.+

~Barb

~Barb at Rocky Mountain Training
Frans v.d. Geest
Community Expert
Community Expert
June 6, 2019

Ah, Barb, also a nice one ;-)