silc_regex_match

SYNOPSIS

    SilcBool silc_regex_match(SilcRegex regexp, const char *string,
                              SilcUInt32 string_len, SilcUInt32 num_match,
                              SilcRegexMatch match, SilcRegexFlags flags);

DESCRIPTION

Finds one or more matches from the `string' using the pre-compiled regular expression `regexp'. It must be compiled by calling the silc_regex_compile before calling this function. The `flags' defines various feature flags.

If only one match is needed the `num_match' may be set to 0 and the `match' is set to NULL. If multiple matches (substrings) are needed the `num_match' defines the size of the `match' array, where each of the matches (with parenthesized regular expression) will be stored. The `match' provides information on where the match was found in `string', providing the start offset and end offset of the match. Unused entires in the array will have -1 as the offset values.

Returns TRUE if the string matched the regular expression or FALSE if it did not match or error occurred. The silc_errno will indicate the error. The silc_errno is set to SILC_ERR_NOT_FOUND if the regular expression did not match.

EXAMPLE

    // Find first match (check if string matches)
    if (!silc_regex_match(&reg, "foo20", 5, 0, NULL, 0))
      no_match;

    // Find multiple matches, one by one
    SilcRegexMatchStruct match;

    while (silc_regex_match(&reg, string, len, 1, &match, 0)) {
      match_string = silc_memdup(string + match.start,
                                 match.end - match.start);
      string += match.end;
    }

    // Parse URI into its components, available in the match[] array
    SilcRegexStruct reg;
    SilcRegexMatchStruct match[7];

    silc_regex_compile(&reg, "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)", 0);
    silc_regex_match(&reg, "http://example.com/page.html", len, 7, match, 0);