Need Help Finding with Regexp
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);
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);
Copy link to clipboard
Copied
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.
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:
- Define a regular expression object for what I want to find. The regular expression has to have the g (global) flag set.
- Loop through each paragraph.
- For each paragraph, get the text of the paragraph.
- Apply the regular express to the text and get a list of matches.
- If there are any matches, I set my doc.TextSelection at the beginning of the paragraph and loop backwards through the matches.
- 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.

