Highlighted

Apply different GREP styles when part of a specific phrase

Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Hi there, I'm having trouble getting this formatting to work correctly. I want to format the phrase “Differences Between The Items” in GREP Style #1 and the word “Items” when it appears by itself in GREP Style #2. What I tried: input “Differences Between The Items” in GREP Style #1 text box and a negative lookbehind in GREP Style #2: (?<!\<Difference Between The\>)\s+\<Items\> . I also tried changing GREP Style #1 to a positive lookbehind. Neither one worked. Do I have the logic wrong, or is it the syntax? Thanks in advance!

Adobe Community Professional
Correct answer by Laubender | Adobe Community Professional

If the properties differ between the two character styles then a negative look behind for the first style should work:

 

TwoGREP-Styles-DifferentPropertiesUsed.PNG

 

Regards,
Uwe Laubender

( ACP )

Topics

How to

Views

408

Likes

Translate

Translate

Report

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

Apply different GREP styles when part of a specific phrase

Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Hi there, I'm having trouble getting this formatting to work correctly. I want to format the phrase “Differences Between The Items” in GREP Style #1 and the word “Items” when it appears by itself in GREP Style #2. What I tried: input “Differences Between The Items” in GREP Style #1 text box and a negative lookbehind in GREP Style #2: (?<!\<Difference Between The\>)\s+\<Items\> . I also tried changing GREP Style #1 to a positive lookbehind. Neither one worked. Do I have the logic wrong, or is it the syntax? Thanks in advance!

Adobe Community Professional
Correct answer by Laubender | Adobe Community Professional

If the properties differ between the two character styles then a negative look behind for the first style should work:

 

TwoGREP-Styles-DifferentPropertiesUsed.PNG

 

Regards,
Uwe Laubender

( ACP )

Topics

How to

Views

409

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 05, 2020 0
Adobe Community Professional ,
May 05, 2020

Copy link to clipboard

Copied

Hi Anthony,

how exactly do you want to format the word "Items" when it stands alone?
How do you want to format the whole phrase “Differences Between The Items”?

 

If you like to use the same property in both cases, e.g. text color, then it's very easy:

Just do the GREP Style for the lonely "Items" first, then, as second GREP Style the style for the whole phrase.

The second GREP Style will overwrite the first one:

 

TwoGREP-Styles-SamePropertiesUsed-TextColor.PNG

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
Adobe Community Professional ,
May 05, 2020

Copy link to clipboard

Copied

If the properties differ between the two character styles then a negative look behind for the first style should work:

 

TwoGREP-Styles-DifferentPropertiesUsed.PNG

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 2
Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Hi Uwe, thanks for the response!! I never thought of reordering the styles, but that worked. So happy to see it doing what it's supposed to.

 

Before I mark it solved, though, I'm curious why the negative lookbehind command didn't work. I tried the more simplified version that you posted but had the same results. I am still interested in this option because I am applying each of the GREP styles to a long list of words (separated by | ). So in the future, I might need to apply the override in the other direction. I guess I could just do a new/ identical GREP style and force the overrides by ordering them manually -- GREP Style #2 (applied to text A, B, C), GREP Style #1, GREP Style #2 (applied to text X, Y, Z) -- but that seems like unnecessary work when this negative lookbehind should be the exact function that I need.

 

Also -- and this may be part of the issue -- I'm not sure what qualifies as a "property" of a GREP style. To answer your question, GREP Style #1 (now #2) is Papyrus. GREP Style #2 (now #1) is Calibri Small Caps. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Nevermind.... I had the negative lookbehind applied to the wrong style. I fixed it and now it's working. Not sure what was wrong with the more complicated version of the negative lookbehind that I posted, but yours works perfectly. Thanks again.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
Adobe Community Professional ,
May 05, 2020

Copy link to clipboard

Copied

Hi Anthony,

when I'm speaking about the properties I am speaking about the properties of the applied Character Style to the GREP Style. A GREP Style has two components: A. The GREP pattern, B. The applied character style.

 

And there is a third component, a meta component if you like, the place of the GREP Style in the stack of other GREP Styles in your paragraph style.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
Adobe Community Professional ,
May 05, 2020

Copy link to clipboard

Copied

And, as you found out, stacking order of styles could be very important.

 

If you go down the order from top to bottom, the bottom most style will win if the applied character styles apply a value for the same character property.

 

In my first example I only used one single character property in my applied character styles, and that property was "fill color of text". The top most style applied a red color to all instances of "Items", the second one applied a cyan color to all instance of the whole phrase. So the red fill color of all instances of "Items" inside the whole phrase were overwritten withe cyan fill color.

 

The more GREP Styles you are adding to one paragraph style the more complicated the situaton gets.

FWIW: It's no good idea to add too much or too complicated ones, because the rendering engine for text will slow down. Especially if you are working with large quantities of text.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 1
Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Uwe, thanks for the careful explanation. You mentioned something that I've heard before... that InDesign doesn't do well with a lot of GREP Style formatting. Unfortunately, I will need to use quite a bit of GREP formatting. Two questions from that: 1) What problems could I run into from a slowing of the rendering engine? 2) Is there another program that would work better?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0
Explorer ,
May 05, 2020

Copy link to clipboard

Copied

Also, with regard to the original example, I have run into some issues downstream of our solution.

 

I have successfully formatted Differences Between The Items in Style #1, and Items by itself in Style #2 using the lookbehind you provided. However, I would also like 1) the word Differences by itself to format in Style #1 and 2) Item singular to format in Style #2. 

 

I got this working by manually adding the strings "Differences" and "Item" to their respective styles -- again following the ordering principle (Items before Item, otherwise the "s" is not formatted). But I'd be interested to know how to do this as a command. 

 

Another fun little bug that has shown up: the GREP Styles are not getting applied to the whole document. To try and fix this, I have selected all and clicked on Basic Paragraph style and checked to make sure there is no + sign appearing anywhere.

 

But maybe I should create a new post for that? Thanks for all your help!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 05, 2020 0