Copy link to clipboard
Copied
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.
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
...Copy link to clipboard
Copied
Hi Kburns:
I'm still learning GREP so perhaps someone else has a more elegant solution but this works:
.+safe.+
~Barb
Copy link to clipboard
Copied
Ah, Barb, also a nice one 😉
Copy link to clipboard
Copied
Ah well...
Grep is magic alright, but mind the spell while casting...
Otherwise, you could turn all Frenchmen into Love symbols while trying to turn frogs into Princes
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Sure Barb!
First I would add (?i) to make the regex case insensitive.
Then I would wrap the keyword with \b word-boundaries. Although it would probably be cool to catch "safety" too, it probably wouldn't be so cool to catch "unsafe".
Finally, I would change "one or more" by "zero or more" in order to handle cases where the keyword starts or ends the paragraph.
This leads us to:
(?i).*\bsafe\b.*
Now, I also could have missed something... That's the beauty of Grep. So powerful, but so picky...
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Thank you [Jongware]​!! This was the perfect solution. I definitely spent 3+ hours last night trying to figure it out, and I definitely wouldn't have come up with this looking at the presets in Indesign.
Copy link to clipboard
Copied
Create Paragraph Styles, search for a word and in Replace choose the correct Paragraph style.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.+ ?
Copy link to clipboard
Copied
(?i).*\b(safe|communities)\b.*
as per Jongware good advice