Copy link to clipboard
Copied
Hi,
I want to format a string within a paragraph with a character format (Zeichenformat), which ends with the first occurrence of a closing brace. How do I have to modify this GREP term ...
\<.+\d\d\d\d, .+\)\.
... to select only the green formatted text without the text formatted in red (and the rest of the paragraph) which contains a second brace in this paragraph:
Bla bla, X., blabla (2022, bla bla 9-11). Bla bla (another brace). Bla Bla.
Thank you!
mycc
Ah. That's why Eugene was asking for real examples. GREP uses pattern matching—we can't come up with a reliable expression without fully understanding all of the options in your file.
Another stab at GREP:
I suspect this can be written more concisely—my GREP knowledge pales in comparision to others helping out in this forum—but in the meantime, see if this holds up in your document.
~Barb
Did some more thinking about this while out walking this morning. This actually can be done with nested styles instead of grep style, you just need two.
First apply the desired character style through 1 )
Next apply the same style through 1 character
This will pick up and format any additional single punctuation mark following the ), or if there is none it will format the space, whcih won't show, so no harm done. This is probably an order of magnitued more efficent than the grep style.
Copy link to clipboard
Copied
Based on your example this works
.+\d+?\).
But we'd need live examples to iron out all the kinks.
Copy link to clipboard
Copied
That was a "live example" 😉
See the selected (green) part in this screenshot: in such a paragraph with two pairs of braces I only want to select from the beginning up to the first closed brace. But your code does the same as my code (only in a more simple way ;-): it selects up to the last closed brace (if there ist more than one brace ...).
The following example works fine, only the green part will be found/selected (to assign a character format):
Bla bla, X., blabla (2022, bla bla 9-11). No further brace. Bla Bla.
Bla bla, X., blabla (2022, bla bla 9-11). Bla bla (another brace). Bla Bla.
... but I only want the green part ...
Copy link to clipboard
Copied
Hi @mycc:
Assuming this is not a exercise in learning GREP, you can accomplish this easily with nested styles. Note that in your live examples you don't seem to want to end each color with the close parenthesis, but instead with the period that follows the closed parenthesis.
Unlike GREP styles, nested styles automatically pick up where the last one left off.
~Barb
Copy link to clipboard
Copied
Thanks again!
But sometimes the green text contains more than one periods 😞
And using two characters is not possible, as I had to try:
Otherwise your tipp with nested styles would have been the smoothiest solution!
Okay, than I have to find and format these exceptions by hand.
Nice weekend!
Copy link to clipboard
Copied
If you can - you should rather switch to permanent assignment - using GREP in ParaStyle formatting will slow InDesign a lot...
Copy link to clipboard
Copied
Ah. That's why Eugene was asking for real examples. GREP uses pattern matching—we can't come up with a reliable expression without fully understanding all of the options in your file.
Another stab at GREP:
I suspect this can be written more concisely—my GREP knowledge pales in comparision to others helping out in this forum—but in the meantime, see if this holds up in your document.
~Barb
Copy link to clipboard
Copied
Try ^[^)]+\)
That should find everything from the start of the paragraph to the first close parentheses.
EDIT: there should not be a ( at the beginning. Not sure how that got there. expression is ^[^)]+\)
Copy link to clipboard
Copied
Your examples look like you might want to capture a period at the end as well after the first close parenthesis, if it exists.
^[^)]+\)\.? should do that
Copy link to clipboard
Copied
Did some more thinking about this while out walking this morning. This actually can be done with nested styles instead of grep style, you just need two.
First apply the desired character style through 1 )
Next apply the same style through 1 character
This will pick up and format any additional single punctuation mark following the ), or if there is none it will format the space, whcih won't show, so no harm done. This is probably an order of magnitued more efficent than the grep style.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now