Copy link to clipboard
Copied
Hi Guys,
I've got this script which is trying to apply a couple of GREPs at once. From what I can tell it should work but for some reason my GREP expressions throw an error.
Can anyone give me some advice as to why it doesn't work?
function proofread () {
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat= "the\s+?(section\s+?\t+?\d+?[.?\d+]?)";
app.changeGrepPreferences.changeTo="$1";
app.activeDocument.changeGrep();
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?i)activity\s+?level";
app.changeGrepPreferences.changeTo="Activity\sLevel";
app.activeDocument.changeGrep();
}
proofread();
Thanks in advance
Try this,
...function proofread () {
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat= "the\\s+?(section\\s+?\\t+?\\d+?[.?\\d+]?)";
app.changeGrepPreferences.changeTo="$1";
app.activeDocument.changeGrep();
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?i)activity\\s+?level";
app.changeGrepPreferences.changeTo="Activity\\sLevel";
app.activeDocument.changeGrep();
app.findGrepPreferences=
Copy link to clipboard
Copied
Try this,
function proofread () {
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat= "the\\s+?(section\\s+?\\t+?\\d+?[.?\\d+]?)";
app.changeGrepPreferences.changeTo="$1";
app.activeDocument.changeGrep();
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat="(?i)activity\\s+?level";
app.changeGrepPreferences.changeTo="Activity\\sLevel";
app.activeDocument.changeGrep();
app.findGrepPreferences=app.changeGrepPreferences=null;
}
proofread();
Alternate method:
findChange("the\\s+?(section\\s+?\\t+?\\d+?[.?\\d+]?)", "$1");
findChange("(?i)activity\\s+?level", "Activity\\sLevel");
function findChange(findWhat, changeTo) {
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
if (findWhat) {
app.findGrepPreferences.findWhat = findWhat;
}
if (changeTo) {
app.changeGrepPreferences.changeTo = changeTo;
}
app.activeDocument.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
}
Copy link to clipboard
Copied
Wow thanks Sajeev.
You even managed to make the script easier to read!
So is it Javascript in general where you have so double \\ to escape characters using GREP?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now