Skip to main content
March 27, 2018
Answered

GREP straight quote javascript translation

  • March 27, 2018
  • 4 replies
  • 1184 views

...Trying to find/replace the below, but extend script errors on the straight quotes expression — so how do I get javascript to recognize straight quotes " ?

Attempted searching via google but things got complex and messy real fast, so figured I would ask the source.

Thanks again everyone.

//reset GREP preferences

app.findGrepPreferences=app.changeGrepPreferences=null;

app.findGrepPreferences.findWhat="(?<=\\d)~}";

//app.changeGrepPreferences.changeTo="~"";

app.changeGrepPreferences.changeTo="~"";

app.activeDocument.changeGrep();

This topic has been closed for replies.
Correct answer Trevor:

You need to escape the " the easiest way of doing that is app.changeGrepPreferences.changeTo='~"'; or you could use app.changeGrepPreferences.changeTo="~\"";

if you are addicted to "double quotes"

4 replies

March 28, 2018

Both of these suggestions worked — funny thing is I previously attempted the single quotes and it failed on me — guess I must have been careless somewhere, in any event thank you so much. Cheers.

Trevor:
Trevor:Correct answer
Legend
March 28, 2018

You need to escape the " the easiest way of doing that is app.changeGrepPreferences.changeTo='~"'; or you could use app.changeGrepPreferences.changeTo="~\"";

if you are addicted to "double quotes"

Trevor:
Legend
March 28, 2018

app.findGrepPreferences.findWhat="\\x{22}";

Not forgetting to escape the \

Peter Kahrel
Community Expert
Community Expert
March 28, 2018

Or use single quotes for the string instead of double quotes:

app.changeGrepPreferences.changeTo = '~"';

Spoilt for choice!

Liphou
Inspiring
March 28, 2018

Hi Bonjour

app.findGrepPreferences.findWhat="(?<=\\d)\\x\{0022\}"; 

 

 

app.changeGrepPreferences.changeTo="”"; 

 

app.activeDocument.changeGrep(); 


A+

Stephen Marsh
Community Expert
Community Expert
March 28, 2018

Why the double double quotes?

Null is not an object…

I can’t script, so I’ll be interested in the replies!