Skip to main content
Participating Frequently
October 28, 2021
Answered

Find/Replace « GREP help

  • October 28, 2021
  • 4 replies
  • 1040 views

Hello !

 

I'm a total newbie at using GREP and I tweaked the FindChangeByList script to find and replace a bunch of little things like double spaces, thin spaces before some punctuations mark, etc.

 

Everything works like a charm EXCEPT for the the double quotes « and ».

 

Here is one of the scripts that I use and that works perfectly well :

grep {find what:" [?]"} {change to:"~<[?]"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Find all space-question mark and replace with a thin space-question mark.
text {find what:"[?]"} {change to:"?"} {include footnotes:true, include master pages:true, include hidden
layers:true, whole word:false} Find all brackets-question marks-brackets and replace with a question mark.
 
(I needed to put the question mark between brackets because it didn't work without. No clue why as I don't know the first thing about GREP).
 
I used the exact same lines and replaced [?] by [«] to apply it to «, but it doesn't work. I've roamed the internet for an answer, and none of what I tried worked.
 
Does anyone out here have a clue why and might be able to help ?
 
Thanks : )
This topic has been closed for replies.
Correct answer jmlevy
quote

Just noticed there was an error in the script syntax, which I corrected to : 

text {find what:"« "} {change to:"«~<"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false} Remplace guillemet-ouvrant-espace par guillemet-ouvrant-espace-fine.


I am not a scripter at all, but a long time user of this script and I have adapted many times the FindChange text which is associated to this script. So, no, it is not an error: you use the ~ metacharacter when the string is a grep one, but as you have seen in my answer, it is a text string and the metacharacter you need to use is ^, not ~.

 

I can guarantee you that the FindChange text file I use (and the 2 lines I gave you are extracted of this text file) works perfectly.

May I ask if you are a French speaking person and if you want to use French typographic rules? If this is the case, I invite you to download this version of the script here:

https://www.abracadabrapdf.net/utilitaires/utilitaires-indesign/indesign-jsfindchangelist-en-version-francaise/

 

I have modified many times this file to match with different needs and it has always worked perfectly, so maybe your error comes from the javascript itself, but unfortunately I cannot help you on this matter.

4 replies

Participating Frequently
November 2, 2021

Hey @Manan Joshi and @jmlevy 

 

So I finally figured out what was wrong! I was using the applescript file and not the javascript ! 

 

@jmlevy I used the file you suggested in javascript and it works like a charm !

 

Thank you both for you precious advice and time : )

Participating Frequently
October 29, 2021

Hey @Manan Joshi and @jmlevy  ! Thank you both for you replies.

 

So I tried both, but I get errors… 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

@jmlevy yes, I absolutely want a thin space after the («) and before the (»). I have no clue why it works fine with the rest of my script, but not the quote. 

 

I attached the full script. Maybe there's something somewhere that I'm not seeing !

 

Thanks for your help : )

 

 

Community Expert
October 29, 2021

Hi @Electric_code5E7B

The attached file works for me, try it. If it still does not work then share a sample InDesign file that we can test with.

-Manan

Participating Frequently
October 29, 2021

Hey @Manan Joshi I just tried it and still nothing : (

 

I created a blank document to try it in, and nothing happened. When I used my old file, the ? worked.

I attached it if you want to try.

 

I'm so confused haha.

jmlevy
Community Expert
October 28, 2021

What dou you want to finally get? A thin space after the opening quote («) and before the closing one (») ?

This works fine, using the FindChangeByList script

text {findWhat:"« "} {changeTo:"«^<"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:false, wholeWord:false} Remplace guillemet-ouvrant-espace par guillemet-ouvrant-espace-fine.
text {findWhat:" »"} {changeTo:"^<»"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:false, wholeWord:false} Remplace espace guillemet-fermant par espace-fine-guillemet-fermant.

 

Note that this text file comes from JRBoulay web site, who adapted the original one to match the French typographic rules

Community Expert
October 28, 2021

In place of [?] use \? you need to escape characters that have special meaning in GREP and ? is one such character so that needs escaping, the escaping is not needed inside a character class that is why enclosing it seems to work for you. For the other replacement just use the character it is not a special character so it would need any escaping nor does it need to be inside a character class

 

In your first example you are replacing "all space-question mark with a thin space bracket open question mark backet close". Due to this reason you need the second text replace. Instead you could use just a single ind/replace like the following

grep {find what:" \?"} {change to:"~<?"} {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}

-Manan