Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Grep Styles for an Entire Paragraph

Community Beginner ,
Jun 06, 2019 Jun 06, 2019

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.

Screen Shot 2019-06-06 at 8.24.22 AM.png

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.

1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 06, 2019 Jun 06, 2019

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

...
Translate
Community Expert ,
Jun 06, 2019 Jun 06, 2019

Hi Kburns:

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

.+safe.+

Screen Shot 2019-06-06 at 6.58.00 AM.pngScreen Shot 2019-06-06 at 6.58.12 AM.png

~Barb

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2019 Jun 06, 2019

Ah, Barb, also a nice one 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 06, 2019 Jun 06, 2019

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

safe.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2019 Jun 06, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 06, 2019 Jun 06, 2019

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2019 Jun 06, 2019

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2019 Jun 06, 2019
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2019 Jun 06, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2019 Jun 06, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2019 Jun 06, 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.+ ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 06, 2019 Jun 06, 2019

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

as per Jongware good advice

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines