Skip to main content
Brainiac
June 18, 2025
Answered

Need help with a GREP

  • June 18, 2025
  • 2 replies
  • 607 views

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.

Correct answer Peter Kahrel

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

2 replies

Adobe Expert
June 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"

Doc MaikAuthor
Brainiac
June 18, 2025

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

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

Peter KahrelCorrect answer
Adobe Expert
June 18, 2025

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

Doc MaikAuthor
Brainiac
June 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. 

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

 

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