Skip navigation
Ranjan_123_singh
Currently Being Moderated

Searching GREP expression through scripts

Apr 23, 2012 4:05 AM

<note id=”law-(\d+)-note-(\d+)” type=”footnote”>

//-------------------------------------------------------

Hi,

        Using the above syntax in the code written below, I am trying to search all the note id's from footnotes, only through scripting. But every time I run it I am getting an error "d is undefined" . Please anyone tell me how to do it.

 

code

//-----------------

var myDocument = app.activeDocument;

var myStory = app.documents.item(0);

app.findGrepPreferences = null;

app.changeGrepPreferences = null;

app.findChangeGrepOptions.includeFootnotes = true;

app.findChangeGrepOptions.includeHiddenLayers = true;

app.findChangeGrepOptions.includeLockedLayersForFind = true;

app.findChangeGrepOptions.includeLockedStoriesForFind=true

app.findChangeTextOptions.wholeWord = false;

 

var test2="<note id=\"law-"+"\\"+d+"-note-"+"\\"+d+"\""+" "+"type=\"footnote\">"

app.findGrepPreferences.findWhat =test2

app.select(app.activeDocument.textFrames.item(0).findGrep())

 

app.findGrepPreferences = null;

app.changeGrepPreferences = null;

//------------------------------

 
Replies
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Apr 23, 2012 4:31 AM   in reply to Ranjan_123_singh

    I don't see how this could possibly work.

    Can you please post a screenshot of what you are searching for in InDesign, with Show HIdden Characters enabled?

    But it looks like you're searching for an XML representation, I don't see how that could ever work.

     

    var test2="<note id=\"law-"+"\\"+d+"-note-"+"\\"+d+"\""+" "+"type=\"footnote\">"

    This produces an error because it references the variable "d".

    I don't know what you're trying to do, but you are concatenting several strings to form test2. Let's write it like this:

     

    var test2="<note id=\"law-"+
         "\\"+
         d+
         "-note-"+
         "\\"+
         d+
         "\""+
         " "+
         "type=\"footnote\">"
    

     

    Again, I don't know what you intend, but that clearly references the contents of a variable called 'd', which does not exist.

    I suppose you want something like "\\d+" instead of "\\"+d but that's just not going to work either, for other reasons....

     

    I would probably write the regexp as

     

    var test2=/<note id=”law-(\d+)-note-(\d+)” type=”footnote”>/.source;
    

     

    which should (hopefully) solve your quoting problems...but it still won't work.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Apr 23, 2012 10:00 PM   in reply to Ranjan_123_singh

    Well, if that's the case, my example ought to work.

    THough...I seem to have ended up with curly-quotes somehow. Did you make them straight-quotes? That's probably necessary. i.e.

     

    var test2=/<note id="law-(\d+)-note-(\d+)" type=”footnote”>/.source;

     

    not

     

    var test2=/<note id=”law-(\d+)-note-(\d+)” type=”footnote”>/.source;

     

    anyhow, in my first reply, I asked:

    Can you please post a screenshot of what you are searching for in InDesign, with Show HIdden Characters enabled?

     

    It would be good for you to do that.

    If the above test2 expression does not work, you should try simplifying it until it does work.

    Start with

     

    var test2=/<note id="law->/.source;

     

    and make sure that works, and then continue adding in pieces.

    It might be helpful to print it out with

     

    $.writeln(test2);

     

    so you understand what's going on.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Apr 24, 2012 6:07 AM   in reply to Ranjan_123_singh

    Ranjan, I can't help you if you do not answer my questions.

     

     

    Please reread my responses and answer the questions I asked you, especially the ones in boldface.

     

    Check, also, the suggested $.writeln() output, and simplifying the regular expression and cutting it down.

     

    Again: Help us, help you. Thank you.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points