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

GREP Replace Multiline Text

Enthusiast ,
May 17, 2021 May 17, 2021

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
562
Translate
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

Just for comment:

 

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

and

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

 

(^/)  The Jedi

Translate
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
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.

Translate
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