Skip to main content
Fightergator
Inspiring
September 12, 2022
Question

Using Customization Flags in RegExp

  • September 12, 2022
  • 1 reply
  • 399 views

A few weeks back a couple of the experts suggested using customization flags in my regular expressions.  I can manually configure my find function, but having no success using qFlags to customize my searches.  Would appreciate any suggestions.  Here's what I have so far:

getRegex ("[0-9][0-9][0-9] [A-Z]", "Green", 0, 1, 0, 1)  
// bRegEx = 0, bCase = 1, bWord = 0, and bWild = 1

function getRegex (regex, color, bRegEx, bCase, bWord, bWild) {   
    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;  // searchstring variable
    findParams[0] = propVal;

if (bWord || bCase || bBack || bRegEx || bWild) { 
    propVal = new PropVal ();
    propVal.propIdent.num = Constants.FS_FindCustomizationFlags;
    propVal.propVal.valType = Constants.FT_Integer;
    propVal.propVal.ival = 1
qFlags = 0;
    if (bCase)  { propVal.propVal.ival | Constants.FF_FIND_CONSIDER_CASE;} // 0x01
    if (bRegEx) { propVal.propVal.ival | Constants.FF_FIND_USE_REGEX;      // 0x10
        propVal = new PropVal ();
        propVal.propIdent.num = Constants.FS_RegexFlavour;
        propVal.propVal.valType = Constants.FT_Integer;
        propVal.propVal.ival = Constants.FR_USE_PERL; 
        findParams[2] = propVal;
    } else {
          if (bWild)  { propVal.propVal.ival|Constants.FF_FIND_USE_WILDCARDS;} // 0x04
          if (bWord)  { propVal.propVal.ival|Constants.FF_FIND_WHOLE_WORD;}    // 0x02
    }
     findParams[1] = propVal;
}
    propVal = new PropVal ();
    propVal.propIdent.num = Constants.FS_FindWrap;
    propVal.propVal.valType = Constants.FT_Integer;
    propVal.propVal.ival=0;
    findParams[3] = propVal;
 
   foundText = doc.Find(tloc, findParams);
   
while (foundText.beg.obj.ObjectValid() && FA_errno == Constants.FE_Success) {  
 
    This topic has been closed for replies.

    1 reply

    frameexpert
    Community Expert
    Community Expert
    September 13, 2022

    This is a function that I use:

    function getRegexFindParams (regex) {
        
        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;
    
        return findParams; 
    }
    
    Fightergator
    Inspiring
    September 13, 2022

    Sorry, I didn't explain my problem better.  I can do RegEx find using the code you provided; can even tweak the code to add a parameter to Consider Case. I'm trying customize individual searches along the lines of something K. Daube sent me a few weeks back.  It uses If/Else cond. statements and qFlags to compile FindCustomizationFlags to tailor the search; e.g., find using RegEx w/wo Consider Case, or find use Wildcards w/wo Consider Case and w/wo Whole Word.  I've gone through every find/replace discussion I can find, including a long discussion back in Aug 2011 when K. Daube was struggling with this himself.  Just can't seem to work it out.  My problem is I simply don't understand the logic behind the find parameters...I can tweak something I find on the forum, or that someone sends me, but I don't understand the logic. 

    frameexpert
    Community Expert
    Community Expert
    September 13, 2022

    When you choose Regular Expressions in the Find/Change dialog box, you will see that Whole Word is grayed out. If you want a whole word search, you can specify it in your regular expression. I think Perl uses \b for word boundaries. So if you wanted to find the whole word "paragraph" (for example), the regular expression would be \bparagraph\b.

     

    Wildcards are a pre-Regular Expressions way of finding simple patterns in FrameMaker text. So you wouldn't use Wildcards with a Regular Expressions search since regular expressions provide much more pattern matching functionality than Wildcards.

     

    So, it may be that specifying Whole Word and Wildcards properties in the parameters are causing it to fail.