It depends on what you want to do once you find the text. Here is a way to just see if the text matches.
#target framemaker
var doc, regex, textRange, text;
// Get the document object and the selected text range.
doc = app.ActiveDoc;
textRange = doc.TextSelection;
// A regular expression of the text I want to find.
regex = /what I want to find/;
// Get the text of the text range.
text = getText (textRange, doc);
// See if the text contains the regular expression.
if (regex.match (text) === true) {
alert ("I found it!");
}
function getText (textObj, doc) {
// Gets the text from the text object or text range.
var text = "", textItems, i;
// Get a list of the strings in the text object or text range.
if (textObj.constructor.name !== "TextRange") {
textItems = textObj.GetText (Constants.FTI_String);
}
else {
textItems = doc.GetTextForRange(textObj, Constants.FTI_String);
}
// Concatenate the strings.
for (i = 0; i < textItems.len; i += 1) {
text += (textItems[i].sdata);
}
return text; // Return the text
}