Copy link to clipboard
Copied
Dear Professionals ..
I wrote very simple code to search for any numbers and put them into brackets and the GREP code is working in Find/Change but not in javascript at all and no errors
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(\d+)";
app.changeGrepPreferences.changeTo="($1)";
app.activeDocument.changeGrep();
So Whats Wrong i do?
Best Regards
Mohammad Hasanin
1 Correct answer
Hi medos20,
Obviously your grep will not find digit because in JavaScript String "(\d+)" will act like "(d+)" because first slace will act like escape character, So you can change your grep to "(\\d+)".
Try this code sample:
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(\\d+)";
app.changeGrepPreferences.changeTo="($1)";
app.activeDocument.changeGrep();
Best
Sunil
Copy link to clipboard
Copied
Hi medos20,
Obviously your grep will not find digit because in JavaScript String "(\d+)" will act like "(d+)" because first slace will act like escape character, So you can change your grep to "(\\d+)".
Try this code sample:
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(\\d+)";
app.changeGrepPreferences.changeTo="($1)";
app.activeDocument.changeGrep();
Best
Sunil
Copy link to clipboard
Copied
Thank you very much sunail, you saved me..Thanks again
Best Regards
Mohammad
Mohammad Hasanin
Copy link to clipboard
Copied
Hi Mohammad,
there is a simple way to debug your GREP expression. Just run e.g. this code on InDesign:
app.findGrepPreferences.findWhat="(\d+)";
Then go to InDesign and open the GREP Find/Change panel in the GUI.
You'll see that in the find field there is just d+ visible and not the pattern you want: \d+.
Regards,
Uwe Laubender
( ACP )

