Skip to main content
Inspiring
November 8, 2022
Answered

Script issue: Find/Change is not recognizing the full GREP expression

  • November 8, 2022
  • 1 reply
  • 465 views

Hi everyone,


Can anyone help me with a script issue? Somehow, my Find/Change is not recognizing the full GREP expression "([\S\s]+)\K\1" when I run the code on Extendscript Toolkit. As shown in the screenshot below, the backslaches and number "1" are missing. Also, I'm unable to include "Condition 1" on Change Format. It seems this line "app.changeGrepPreferences.appliedConditions = "Condition 1"" is not correct.  Here's the script:

var doc = app.activeDocument;

app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat = "([\S\s]+)\K\1";
app.findGrepPreferences.appliedCharacterStyle = "Character Style 1";
app.changeGrepPreferences.changeTo = "";
app.changeGrepPreferences.appliedCharacterStyle = "Character Style 2";
app.changeGrepPreferences.appliedConditions = "Condition 1"
doc.changeGrep();


Thanks in advance,
Rogerio

This topic has been closed for replies.
Correct answer m1b

The error says it expects an Array so could you try 

 

app.changeGrepPreferences.appliedConditions = ['Condition 1'];

 

- Mark 

1 reply

m1b
Community Expert
Community Expert
November 8, 2022

You have to escape the backslashes in the grep pattern string, eg.

app.findGrepPreferences.findWhat = "([\\S\\s]+)\\K\\1";

(I'm not able to test right now, but that is definitely one issue.)

- Mark

Inspiring
November 8, 2022

Hi Mark,

It worked like magic! Thanks for that 🙂

Could you also help me to figure out how to fix this?

Thanks,
Rogerio



m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
November 8, 2022

The error says it expects an Array so could you try 

 

app.changeGrepPreferences.appliedConditions = ['Condition 1'];

 

- Mark