LabWindows/CVI

Low-level Class Help

This class contains functions for parsing a regular expression, matching it to the beginning of a text buffer, and destroying it. For many cases, the high–level function RegExpr_FindPatternInText is sufficient. In those cases where it is not, the functions in this class are useful.

The example below shows how to use the functions in this class to implement a simplified (and somewhat modified) version of FindPatternInText.

int FindPatternInText (
char *regExpr, /* must be nul-terminated */
int caseSens,
int matchPolicy,
char *text, /* ASSUME: nul-terminated */
int *matchCol,
int *matchLen)
{

RegExprHandle handle
int matched, retVal;

matched = FALSE;
*matchCol = -1;
*matchLen = -1;

retVal = RegExpr_Parse (regExpr, caseSens, &handle);
if (retVal < 0)
     printf ("Error parsing regular expression %s\n(%s)\n", regExpr,
             RegExpr_GetErrorElaboration());
else

{
int textLen = strlen(text);
int done = FALSE;
int i;

for (i=0; i < textLen && !done; i++)

{
switch (RegExpr_MatchText (handle, text+i, textLen-i,
                           matchPolicy, matchLen))
    {
    case RegExpr_Match:
         matched = TRUE;
         *matchCol = i;
         done = TRUE;
         break;
    case RegExpr_NoMatch:
         break;
    case RegExpr_NotInText: /* optimization */
         done = TRUE;
         break;
    }
}

RegExpr_Destroy (handle);
}

return matched;

}

Library: Regular Expressions Control