• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

GREP Replace Multiline Text

Enthusiast ,
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

257

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
Guide ,
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

Votes

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
Enthusiast ,
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.

Votes

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