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

Need help with a GREP

Guide ,
Jun 18, 2025 Jun 18, 2025

Hello!

I use a lot of cross-refs which consist of a chapter number and some text, separated by a space and everything enclosed in quotation marks. Example: "1.1 This is an example"

I made a GREP to find them:  (")(\d+.+?) (.+?)(")

For some reason, using the placeholders for left and right double quotation marks doesn't work in my document, but in another, so I used the "any" placeholder. So far, this GREP finds all cross-refs.

 

However, it's supposed to stop at the end, at the right double quotation mark that encloses the cross-ref.

Some of the headlines the cross-refs are made from also contain their own quotation marks, so that some of the cross-refs turn out as: "1.1 This is "another" example"

 

What happens when using the GREP? It would stop at the first right quotation mark. I have tried a lot, but I cannot find the correct extension for my GREP, to sort of skip both or all of the inner quotation marks. 

 

Anyone has a solution, other than to replace the double quotation marks in the headlines by single ones? This would of course solve the problem. Thanks in advance.

TOPICS
Type
311
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 1 Correct answer

Community Expert , Jun 18, 2025 Jun 18, 2025

Those 'unconditional' spaces are in fact variable-width non-breaking spaces. You use ~S for them in a grep expression.

Translate
Guide ,
Jun 18, 2025 Jun 18, 2025

As a nasty addition, in a French document the quotation marks are followed/led by an unconditional space, put by the translator: 

DocMaik_0-1750262349071.png

I also couldn't find a wildcard or placeholder that would include that unconditional space.  (") (\d+.+?) (.+?) (") and (".)(\d+.+?) (.+?)(.") don't work.

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 ,
Jun 18, 2025 Jun 18, 2025

Those 'unconditional' spaces are in fact variable-width non-breaking spaces. You use ~S for them in a grep expression.

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
Guide ,
Jun 23, 2025 Jun 23, 2025

Thanks. As I'm currently digging deeper into GREP than ever before, I have a lot to learn.

My thinking now was to OR the search to either find the quotation mark or the mark follow by that special space.

So I made this: (["]|["~S])(\d+.+?) (.+?)([~S"]|["])

It works, but for the French document it now wouldn't include the outer quote anymore. 

DocMaik_0-1750663772683.png

I actually don't see why, because only ["~S] and [~S"] fulfill the pattern.

 

Update: this seems to do it: ("|"~S)(\d+.+?) (.+?)(~S"|")

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 ,
Jun 23, 2025 Jun 23, 2025

I don't understand your "|" at all. The expression works, but I've no idea why and how.

 

To match the number, instead of (\d+.+?) it feels safer to use [\d.]+ 

Also, you need parentheses for grouping only if you reference the groups. Leaving them out when they're not needed makes the expression more readable. Here's a simpler version of your expression:

 

"~S[\d.]+ .+?~S"

 

>  I have a lot to learn.

 

It's worth all your trouble. There are various web sites with training material. For a comprehensive guide, see https://creativepro.com/now-available-grep-in-indesign-3rd-edition/

 

 

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
Guide ,
Jun 23, 2025 Jun 23, 2025
quote

I don't understand your "|" at all. The expression works, but I've no idea why and how.

By @Peter Kahrel

As far as I learned, everything after the | is used, until delimited. So it's, in words, "quotation mark OR quotation mark followed by unconditional space". 

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 ,
Jun 23, 2025 Jun 23, 2025

Oops! Of course! But in your "|"~S it means 'quotation mark OR quotation mark, followed by ~S', which doesn't make much sense and explains why the closing quote isn't found. Your [~S"]|["] says '~S or quote followed by quote'. Remember that [~S"] and ~S|" are equivalent.

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
Guide ,
Jun 23, 2025 Jun 23, 2025
quote

Remember that [~S"] and ~S|" are equivalent.

Hmm... I knew that, but had in mind the expression in brackets is AND, not OR.

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 ,
Jun 23, 2025 Jun 23, 2025
LATEST

The character class is tested against single characters, which can only be one OR the other.

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
Guide ,
Jun 23, 2025 Jun 23, 2025

To match the number, instead of (\d+.+?) it feels safer to use [\d.]+ 

I think that wouldn't include two- or three-digit numbers. 

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 ,
Jun 23, 2025 Jun 23, 2025

It would. It's a character class, saying 'a string consisting of digits and/or dots'.

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 ,
Jun 18, 2025 Jun 18, 2025

There is a grep modifier to find matching characters (brackets, quotation marks) but they won't help you here I don't think.So you'd probably need a script for things like "1.1 This is "another" example"

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