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

GREP: select text up to the first occurence of a specific char

Participant ,
Mar 17, 2023 Mar 17, 2023

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

TOPICS
How to
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 2 Correct answers

Community Expert , Mar 17, 2023 Mar 17, 2023

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:

2023-03-17_11-38-16.png

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

Translate
Community Expert , Mar 18, 2023 Mar 18, 2023

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.

Translate
Community Expert ,
Mar 17, 2023 Mar 17, 2023

Based on your example this works

.+\d+?\).

 

But we'd need live examples to iron out all the kinks.

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
Participant ,
Mar 17, 2023 Mar 17, 2023

That was a "live example" 😉

mycc_0-1679065669656.png

 

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.

 

  1. But in my first example, the red part is also selected, because of the second pair of braces:

Bla bla, X., blabla (2022, bla bla 9-11). Bla bla (another brace). Bla Bla.

 

... but I only want the green part ...

 

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 ,
Mar 17, 2023 Mar 17, 2023

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. 

2023-03-17_09-55-51.png

Unlike GREP styles, nested styles automatically pick up where the last one left off.  

 

~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
Participant ,
Mar 17, 2023 Mar 17, 2023

 

Thanks again!

But sometimes the green text contains more than one periods 😞

 

And using two characters is not possible, as I had to try:

mycc_0-1679071258704.png

 

 

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! 

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
LEGEND ,
Mar 17, 2023 Mar 17, 2023

If you can - you should rather switch to permanent assignment - using GREP in ParaStyle formatting will slow InDesign a lot... 

 

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 ,
Mar 17, 2023 Mar 17, 2023

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:

2023-03-17_11-38-16.png

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

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 ,
Mar 17, 2023 Mar 17, 2023

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 ^[^)]+\)

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 ,
Mar 17, 2023 Mar 17, 2023

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

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 ,
Mar 18, 2023 Mar 18, 2023
LATEST

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.

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