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

Using Customization Flags in RegExp

Contributor ,
Sep 12, 2022 Sep 12, 2022

Copy link to clipboard

Copied

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) {  
 

Views

103

Translate

Translate

Report

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
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

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; 
}

Votes

Translate

Translate

Report

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
Contributor ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Contributor ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

LATEST

Yes, you're correct.  However, I'm trying to use a single function to do everything (but not all at once), rather than calling multiple functions based on how I want to search.  For example, tell the find function to use RegExp and then selectively turn Consider Case on/off using a variable; e.g. bCase.  With the same function, use Wildcards instead of RegExp and select Consider Case and/or Whole Words with variables passed to the function.  BTW, thanks for the tip on \b \b to get whole words...I hadn't considered that as a workaround. K. Daube sent me this a while back, which is what I'm trying to incorporate, assuming I understand it right...

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);

 

Votes

Translate

Translate

Report

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