# Regular Expressions Control

toolslib\toolbox\regexpr.fp

This instrument driver allows you to search text for patterns that match regular expressions.

There are two ways you can program with regular expressions. At the high level, you can call RegExpr_FindPatternInText, which searches a text buffer for a match to a regular expression. This function parses the expression, iteratively tries to match the expression to subsequent positions in the text buffer, and then destroys the regular expression parse tree.

At the low level, you can call separate functions for parsing a regular expression, matching the expression to the beginning of a text buffer, and destroying the parse tree. The Low-level class help contains an example of how to use the low-level functions.

The following example demonstrates how to use the high-level function.

char *text;

int textLen, caseSens, matchPolicy;

int handle, matched, matchPosition, matchLen;

/* set values for text, textLen, caseSens, matchPolicy */

if (RegExpr_FindPatternInText (regExpr, caseSens, text, textLen, RegExpr_SearchForwards, matchPolicy, &matched, &matchPosition, &matchLen) < 0)

printf ("Error parsing regular expression %s\n(%s)\n", regExpr, RegExpr_GetErrorElaboration());

else

if (matched)

printf ("Match found at index=%d, length=%d"\n, matchPosition, matchLen);

else

printf ("No match found\n".);