Skip to main content
New Participant
May 17, 2022
Answered

Grep find/replace not working like it used to

  • May 17, 2022
  • 1 reply
  • 513 views

I'm trying to figure out if there's been a change with InDesign CC 2021, or if there's something else at play. We have a script that used to take delete a line of text and replace with a space - it is leaving the line in now:

 

app.findGrepPreferences.findWhat = "ALL CONTENT MUST BE AFTER THIS LINE - DO NOT REMOVE";
app.changeGrepPreferences.changeTo = "";
selectedText.changeGrep();
This topic has been closed for replies.
Correct answer Sally5C0E

Thanks @Sally5C0E. I tested by importing your .rtf file and it works as expected (Indesign 17.2.1, MacOS 12.3.1).

 

Could you please make a new document, import .rtf file and test your code? And if it doesn't work with that, please post that indesign file that fails? And your test code? Then we can get to the bottom of it.

- Mark

 


We have to use InDesign V 16. I just did an update to 16.4.2 and it is working again. Thanks for looking into this!

1 reply

m1b
Community Expert
May 17, 2022

Hi @Sally5C0E, I tested that code and it worked as expected for me (replaced the findWhat text with nothing). Here's the exact code I tested:

var doc = app.activeDocument,
    selectedText = doc.selection[0];

app.findGrepPreferences.findWhat = "ALL CONTENT MUST BE AFTER THIS LINE - DO NOT REMOVE";
app.changeGrepPreferences.changeTo = "";
selectedText.changeGrep();

Are you getting an error? Have you double-checked the findWhat string does match the document text? Perhaps you could post a sample document?

- Mark

 

Sally5C0EAuthor
New Participant
May 17, 2022

Yes, the document text does match - here's a sample text document.

Sally5C0EAuthorCorrect answer
New Participant
May 17, 2022

Thanks @Sally5C0E. I tested by importing your .rtf file and it works as expected (Indesign 17.2.1, MacOS 12.3.1).

 

Could you please make a new document, import .rtf file and test your code? And if it doesn't work with that, please post that indesign file that fails? And your test code? Then we can get to the bottom of it.

- Mark

 


We have to use InDesign V 16. I just did an update to 16.4.2 and it is working again. Thanks for looking into this!