Copy link to clipboard
Copied
I have a consistent paragraph that I wanted to replace and I was having trouble getting InDesign scripting to cooperate. A simple GREP query that worked in InDesign, did not in scripting. After some trial and error, I found that simply escaping the slashes was what InDesign scripting needed. Posting for anyone trying to solve a similar problem, most likely me in a few years. 😄
Sample Query for search:
Hello[\w\W]*the end.
Sample Text:
Hello Blah Blah Blah
Blah
Testing
Blah Blah Blah the end.
Sample InDesign Javascript/Extendscript:
app.findGrepPreferences.findWhat = "Hello[\\w\\W]*the end.";
app.changeGrepPreferences.changeTo = "YOU DID IT";
app.activeDocument.changeGrep();
Note to Adobe Javascript followed by a : replaces automatically as Javascript: within the forums. If this note looks normal, t the : problem has been fixed.
Copy link to clipboard
Copied
Just for comment:
Hello[\w\W]*the end\.
and
"Hello[\\w\\W]*the end\\."
(^/) The Jedi
Copy link to clipboard
Copied
Thanks! It also appears triple slashes work for the script as well:
Hello[\\\w\\\W]*the end\\\.
Anything more than that and it stops working. It appears the first 2 are interpreted as a \ and the third escapes whatever follows? The sample provided doesn't scrub the find replace, so I tested a few different outcomes to see what it was parsing.