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

Need Help Finding with Regexp

Contributor ,
Jul 30, 2022 Jul 30, 2022

Copy link to clipboard

Copied

I'm using the code below to find strings using wildcards.  Can anyone point help me figure out how to modify this to search for strings using wildcards?  Been knocking myself out on this for more than a week.  Can't find anything that seems to work.

 

function higherror (searchVar){//this finds and highlights common errors, wildcards on
var doc=app.ActiveDoc //sets the active document as the object
var docStart = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf ; //moves insertion point to start of document
var tloc = new TextLoc (docStart, 0);
var findParams = new PropVals(); // setup find parameters
var searchString = searchVar;

findParams = AllocatePropVals(3);

findParams[0].propIdent.num = Constants.FS_FindCustomizationFlags;
findParams[0].propVal.valType = Constants.FT_Integer;
findParams[0].propVal.ival = 1 | 4;

findParams[1].propIdent.num = Constants.FS_FindText;
findParams[1].propVal.valType = Constants.FT_String;
findParams[1].propVal.sval = searchString;

findParams[2].propIdent.num = Constants.FS_FindWrap;
findParams[2].propVal.valType = Constants.FT_Integer;
findParams[2].propVal.ival = false;

var foundText = doc.Find(tloc, findParams);

Views

122

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 ,
Jul 31, 2022 Jul 31, 2022

Copy link to clipboard

Copied

Hi Fightergator,

Wildcard and RegEx are tro differt things. See https://www.daube.ch/docu/files/FMFindRepl.pdf, pages 17 and 20ff.

Maybe you should first define the propident for TextString, then the dedail, like in the flollowing snippet. But I think, the problem lies in the defintion of the propval for the customisation flags.

 

var findParams, qFlags, oPropVal1, oPropVal2, oPropVal3, oPropVal4, sSearch;

findParams = new PropVals();
oPropVal1 = new PropVal() ; 
// --- NoWrap stops at the iniital find start 
oPropVal1.propIdent.num = Constants.FS_FindWrap ;
oPropVal1.propVal.valType = Constants.FT_Integer;
oPropVal1.propVal.ival = 0 ;   // no wrap
findParams.push(oPropVal1);

oPropVal2 = new PropVal() ;
oPropVal2.propIdent.num = Constants.FS_FindText;
oPropVal2.propVal.valType = Constants.FT_String;
oPropVal2.propVal.sval = sSearch;
findParams.push(oPropVal2);

oPropVal3 = new PropVal() ;
oPropVal3.propIdent.num = Constants.FS_FindCustomizationFlags ;
oPropVal3.propVal.valType = Constants.FT_Integer;
qFlags = 0;
qFlags = qFlags | Constants.FF_FIND_USE_WILDCARDS;  // 0x04
oPropVal3.propVal.ival = qFlags;
findParams.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
Contributor ,
Aug 13, 2022 Aug 13, 2022

Copy link to clipboard

Copied

LATEST

Sorry so long to get back to you...I've been on vacation for the past week.  A question regarding your find code...how do you "Consider Case" in your searches.  I confess, I'm still confused by the whole propVal...num, type, ival thing.  Wish there was something that explained it.    

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 ,
Aug 01, 2022 Aug 01, 2022

Copy link to clipboard

Copied

I do this whole find thing a little bit differently. I will try to post some code later, but I basically do this:

  1. Define a regular expression object for what I want to find. The regular expression has to have the g (global) flag set.
  2. Loop through each paragraph.
  3. For each paragraph, get the text of the paragraph.
  4. Apply the regular express to the text and get a list of matches.
  5. If there are any matches, I set my doc.TextSelection at the beginning of the paragraph and loop backwards through the matches.
  6. For each match, I use the find params and the matched value to return the TextRange of the found text to get the text and then do what I need to with it.

It sounds complicated, but I use functions to make it all work, and I am happy with the results.

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