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