Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


GREP Replace Multiline Text

Engaged ,
May 17, 2021 May 17, 2021

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.

 

TOPICS
Scripting

Views

103

Likes

Translate

Translate

Report

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
Advisor ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

Just for comment:

 

Hello[\w\W]*the end\.

and

"Hello[\\w\\W]*the end\\."

 

(^/)  The Jedi

Likes

Translate

Translate

Report

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
Engaged ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

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