Skip to main content
Fightergator
Inspiring
August 8, 2022
Answered

Need help with "consider case" for regexp searches

  • August 8, 2022
  • 1 reply
  • 220 views

With assistance of forum's Frame Master I've be able to implement the code below to search for regexps. However, I can't seem to set the Consider Case parameter.  I remember an earlier piece of code posted by K. Daube that used qFlags, but I'm not familiar with how they work. Rick mentioned adding an "ig" or "g" to set the global flag at the end of the experession, but it seems to just stip that off when I try passing that to the function. Thoughts?

 

regex = "Widget";
getRegexFindParams (regex)

function getRegexFindParams (regex) { //CP.getRegexFindParams = function (regex) {

doc=app.ActiveDoc;
docStart = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
tloc = new TextLoc (docStart, 0);

findParams = new PropVals ();

propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindText;
propVal.propVal.valType = Constants.FT_String;
propVal.propVal.sval = regex;
findParams[0] = propVal;

propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindCustomizationFlags;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = 16; // Regular expressions
findParams[1] = propVal;

propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_FindWrap;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival=0;
findParams[2] = propVal;

propVal = new PropVal ();
propVal.propIdent.num = Constants.FS_RegexFlavour;
propVal.propVal.valType = Constants.FT_Integer;
propVal.propVal.ival = 1;
findParams[3] = propVal;

foundText = doc.Find(tloc, findParams);
//background highlight found text and get next

    This topic has been closed for replies.
    Correct answer K.Daube

    The customisation flags must be "ored". The following snippet may help you (bWord is true if only full words are to be considere, bCase etc. analogous):

      if (bWord || bCase || bBack || bRegEx || bWild) { 
        oPropVal3 = new PropVal() ;
        oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;
        oPropVal3.propVal.valType = Constants.FT_Integer;
        qFlags = 0;
        if (bCase)  { qFlags = qFlags   | Constants.FF_FIND_CONSIDER_CASE;} // 0x01
        if (bRegEx) { qFlags = qFlags   | Constants.FF_FIND_USE_REGEX;      // 0x10
            oPropVal4 = new PropVal ();
            oPropVal4.propIdent.num = Constants.FS_RegexFlavour;            // 17
            oPropVal4.propVal.valType = Constants.FT_Integer;
            oPropVal4.propVal.ival = Constants.FR_USE_PERL;                 // 1
            findParms.push(oPropVal4);
        } else {
          if (bWild)  { qFlags = qFlags | Constants.FF_FIND_USE_WILDCARDS;} // 0x04
          if (bWord)  { qFlags = qFlags | Constants.FF_FIND_WHOLE_WORD;}    // 0x02
          if (bBack)  { qFlags = qFlags | Constants.FF_FIND_BACKWARDS;}     // 0x08
        }
        oPropVal3.propVal.ival = qFlags; // qFlags OK; ...ival reports error in ESTK
        findParms.push(oPropVal3);

     

    1 reply

    K.Daube
    Community Expert
    K.DaubeCommunity ExpertCorrect answer
    Community Expert
    August 9, 2022

    The customisation flags must be "ored". The following snippet may help you (bWord is true if only full words are to be considere, bCase etc. analogous):

      if (bWord || bCase || bBack || bRegEx || bWild) { 
        oPropVal3 = new PropVal() ;
        oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;
        oPropVal3.propVal.valType = Constants.FT_Integer;
        qFlags = 0;
        if (bCase)  { qFlags = qFlags   | Constants.FF_FIND_CONSIDER_CASE;} // 0x01
        if (bRegEx) { qFlags = qFlags   | Constants.FF_FIND_USE_REGEX;      // 0x10
            oPropVal4 = new PropVal ();
            oPropVal4.propIdent.num = Constants.FS_RegexFlavour;            // 17
            oPropVal4.propVal.valType = Constants.FT_Integer;
            oPropVal4.propVal.ival = Constants.FR_USE_PERL;                 // 1
            findParms.push(oPropVal4);
        } else {
          if (bWild)  { qFlags = qFlags | Constants.FF_FIND_USE_WILDCARDS;} // 0x04
          if (bWord)  { qFlags = qFlags | Constants.FF_FIND_WHOLE_WORD;}    // 0x02
          if (bBack)  { qFlags = qFlags | Constants.FF_FIND_BACKWARDS;}     // 0x08
        }
        oPropVal3.propVal.ival = qFlags; // qFlags OK; ...ival reports error in ESTK
        findParms.push(oPropVal3);

     

    Fightergator
    Inspiring
    August 13, 2022

    Sorry...disregard my previous.  I see you already provide me the answer.  I had forgotten this post.