Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using GREP in Indesign scripts

Engaged ,
Sep 12, 2016 Sep 12, 2016

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

TOPICS
Scripting
766
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Sep 12, 2016 Sep 12, 2016

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=

...
Translate
Enthusiast ,
Sep 12, 2016 Sep 12, 2016

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 12, 2016 Sep 12, 2016
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines