Highlighted

GREP not Working in JavaScript

Engaged ,
Jun 09, 2020

Copy link to clipboard

Copied

Hi Friends,,

I wrote again grep codes running well in Find/Change and not at all in JavaScript,, i dont know whats wrong!, here is the code : 

any Help Please

//Now GREP Come On - Catch any Brackets
alert("Clear all Spaces after and Before Brackets");
//Starting Right
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=\()\x{20}";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//Starting Left
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="\x{20}(?=\))";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//All Operation Done
alert("GREP Operation End");
exit();
Adobe Community Professional
Correct answer by rob day | Adobe Community Professional

You have to escape the backslashes:

 

//Starting Right
app.findGrepPreferences.findWhat=NothingEnum.NOTHING;
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING;
app.findGrepPreferences.findWhat="(?<=\\()\\x{20}";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//Starting Left
app.findGrepPreferences.findWhat=NothingEnum.NOTHING;
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING;
app.findGrepPreferences.findWhat="\\x{20}(?=\\))";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
TOPICS
Scripting

Views

324

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

GREP not Working in JavaScript

Engaged ,
Jun 09, 2020

Copy link to clipboard

Copied

Hi Friends,,

I wrote again grep codes running well in Find/Change and not at all in JavaScript,, i dont know whats wrong!, here is the code : 

any Help Please

//Now GREP Come On - Catch any Brackets
alert("Clear all Spaces after and Before Brackets");
//Starting Right
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?<=\()\x{20}";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//Starting Left
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="\x{20}(?=\))";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//All Operation Done
alert("GREP Operation End");
exit();
Adobe Community Professional
Correct answer by rob day | Adobe Community Professional

You have to escape the backslashes:

 

//Starting Right
app.findGrepPreferences.findWhat=NothingEnum.NOTHING;
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING;
app.findGrepPreferences.findWhat="(?<=\\()\\x{20}";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//Starting Left
app.findGrepPreferences.findWhat=NothingEnum.NOTHING;
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING;
app.findGrepPreferences.findWhat="\\x{20}(?=\\))";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
TOPICS
Scripting

Views

325

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
Jun 09, 2020 0
Adobe Community Professional ,
Jun 09, 2020

Copy link to clipboard

Copied

Check if you have properly escaped special character in the jsx. The easiest way to debug is comment out nullifying the findgrep/changegrep objects run the code and the open Find/Change dialog to verify what is the value in grep and changegrep that was fed by the code.

 

-Manan

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
Reply
Loading...
Jun 09, 2020 0
Adobe Community Professional ,
Jun 09, 2020

Copy link to clipboard

Copied

You have to escape the backslashes:

 

//Starting Right
app.findGrepPreferences.findWhat=NothingEnum.NOTHING;
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING;
app.findGrepPreferences.findWhat="(?<=\\()\\x{20}";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();
//Starting Left
app.findGrepPreferences.findWhat=NothingEnum.NOTHING;
app.changeGrepPreferences.changeTo=NothingEnum.NOTHING;
app.findGrepPreferences.findWhat="\\x{20}(?=\\))";
app.changeGrepPreferences.changeTo="";
app.activeDocument.changeGrep();

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
Reply
Loading...
Jun 09, 2020 2
medos20 LATEST
Engaged ,
Jun 12, 2020

Copy link to clipboard

Copied

Thank you very much indeed

 

best regards

Mohammad

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
Reply
Loading...
Jun 12, 2020 0