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

GREP Style AFTER Forced Line Break

Explorer ,
Nov 01, 2021 Nov 01, 2021

Copy link to clipboard

Copied

I have a paragraph style that has a nested style that triggers after a forced line break. What I would like to happen after is if there is something in parentheses WITHIN the nested style section that gets another different style. 

 

I was able to get this to work just using another nested style, but I watched a MAX class that involved GREP styles and wanted to see if I could make it work. 

 

I got as a far as (\s\(.*?)(.\)\s) which changes the parentheses everywhere and this (?<=\n).+ which changes anything after the forced break.

 

I can't figure out the glue that will make it start the search for open parentheses after the break AND the following characters until it finds the parentheses, then change. 

 

Any ideas or should I just stick to nesting styles?

Screen Shot 2021-11-01 at 16.53.26 .png

TOPICS
How to

Views

2.2K

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
community guidelines

correct answers 2 Correct answers

Community Expert , Nov 02, 2021 Nov 02, 2021

It can be done with two GREP Styles in sequence in your paragraph style.

First: (?<=\n).+ will change all the text following the forced line break. It uses a positive look-behind for that forced line break.

Second: \([^)]+\)(?!\n) will find any string enclosed in parentheses in the text you just changed. This finds the open parenthesis then uses a negative class to add anything not a close parenthesis and finally adds the first close parenthesis it finds. It also uses a negative look-ahead to be

...

Votes

Translate

Translate
Community Expert , Nov 03, 2021 Nov 03, 2021

Just keep in mind that any sort of style can apply only one set of parameters, so no matter whether you use GREP or a regular nested style you cannot make two different changes to the same parameter in the same text in one go.

 

Also, there are at least two methods for finding the shortest match using GREP and I gave you what Peter Kahrel says in his book is the more efficient method for finding text between parentheses which would be a help for a longer doc.

 

In the general sense a GREP style

...

Votes

Translate

Translate
Community Expert ,
Nov 01, 2021 Nov 01, 2021

Copy link to clipboard

Copied

Just so you know, GREP styles are not terribly efficient and can slow down a long document, so ordinary nested styles would be preferable if they will work.

 

Forther, I don't really understand why you are using forced line breaks instead of two real paragraphs with two paragraph styles. These can be set to rotate from one to the other by use of the Next Style setting. This would allow the use of a single nested style in each.

Votes

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
community guidelines
Explorer ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

Thank you for the info and feedback.

 

Like I said previously, I was using nesting styles for the effect with no issue. I wanted to challenge myself to see if I could have the same effect with a GREP style, and since I couldn’t figure the connecting part out, I came here for advice.

 

As for why I'm/ was using forced line breaks, it just made my workflow easier.

 

All that said, do you know how to make it work, or is it even possible? 

Votes

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
community guidelines
Community Expert ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

It can be done with two GREP Styles in sequence in your paragraph style.

First: (?<=\n).+ will change all the text following the forced line break. It uses a positive look-behind for that forced line break.

Second: \([^)]+\)(?!\n) will find any string enclosed in parentheses in the text you just changed. This finds the open parenthesis then uses a negative class to add anything not a close parenthesis and finally adds the first close parenthesis it finds. It also uses a negative look-ahead to be sure there is not a forced line break after the close to keep it from affecting the parenthetical string in the first line.

 

I did not test this on a paragraph that does NOT conform to your sample, so it probably will mis-behave if you don't have a forced line break, or more than one, and will definitely misbehave if you have anything after the parenthesis but before the line break in the fisrt line or a forced break after the close of the second line, but it does work for your case with additional text after the parenthetical you want to change.

GREP Styles sample.png

Votes

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
community guidelines
Explorer ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

Thank you! I thought it would all have to be on one line. You have taught me more than you think. 

 

Apologies if my previous comments sounded disrespectful. I really appreciate your time. 

Votes

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
community guidelines
Community Expert ,
Nov 02, 2021 Nov 02, 2021

Copy link to clipboard

Copied

I don't think this would be possible with a single GREP expression since you want to make two color changes.

And I didn't notice any disrespect.

Votes

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
community guidelines
Explorer ,
Nov 03, 2021 Nov 03, 2021

Copy link to clipboard

Copied

Trying to make it a single expression was what was had me hitting a wall and starting to pull my hair out! Looks like I have a bit (a lot) of studying to do with GREP. I'll keep in mind what you said about GREPs effencency in longer documents. 

 

Thanks again.

Votes

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
community guidelines
Community Expert ,
Nov 03, 2021 Nov 03, 2021

Copy link to clipboard

Copied

Just keep in mind that any sort of style can apply only one set of parameters, so no matter whether you use GREP or a regular nested style you cannot make two different changes to the same parameter in the same text in one go.

 

Also, there are at least two methods for finding the shortest match using GREP and I gave you what Peter Kahrel says in his book is the more efficient method for finding text between parentheses which would be a help for a longer doc.

 

In the general sense a GREP style would be appropriate when you want to match a pattern of text that is not always triggered by the same exact condition, but if there is a particular character, such as a forced line break or parentheses as in your text, and ordinary nested style is better. You could also use a Line Style to apply the primary color change to your text after the break (if your text before the line break isn't more than one line long) in combination with the GREP style. Notice all the "ifs" I've thrown out over the last few posts, though, and you can see where the regular nested styles have an advantage.

Votes

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
community guidelines
Explorer ,
Aug 26, 2024 Aug 26, 2024

Copy link to clipboard

Copied

I stumbled on this thread because I need to create some templates for a third-party app that's populating many paragraphs of text. The apps that contain the text can't re-style for paragraph padding, nor can they account for users paying attention to instructions. Therefore, I needed a solution that didn't hit a dead end or resort to manual find & change. Here's what I'm going to try:

- Create character style "no break" that applies a leading value of 0

- Apply style "no break" to text where the paragraph return is at the beginning of the paragraph:

^~b

 

It does have a minimal additional space, but will be far better than a full double space.
So far the test doc is working well enough to push to a test environment.  See the attached screenshot. 

 

As a hot tip for anyone who tries this: 

Remember to deselect all items in the document and select "[None]" in the Character Styles panel, otherwise all text you type in the document will be invisibly squished with no leading and drive users nuts. I usually hide nested styles like these in a group that prevents people from accidentally clicking on it.

Votes

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
community guidelines
Community Expert ,
Aug 26, 2024 Aug 26, 2024

Copy link to clipboard

Copied

@Danielle McLelland

 

You mean empty lines?

 

Votes

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
community guidelines
Explorer ,
Aug 26, 2024 Aug 26, 2024

Copy link to clipboard

Copied

LATEST

Oh oh! I was comparing two threads and responded to the wrong one. 

Votes

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
community guidelines