Added SILC_STR_REGEX macro to SILC Buffer Format API.
[crypto.git] / lib / silcutil / tests / test_silcregex.c
index 6e79cb0a83346fbd7062a9b589960bf3a48719b1..ba98bbe036ac87007523f9df0931658ad1987a59 100644 (file)
@@ -17,6 +17,28 @@ int main(int argc, char **argv)
     silc_log_set_debug_string("*regex*,*errno*");
   }
 
+  regex = "(H..).(o..)";
+  SILC_LOG_DEBUG(("Regex %s", regex));
+  if (!silc_regex_compile(&reg, regex, 0))
+    goto err;
+
+  string = "Hello World";
+  SILC_LOG_DEBUG(("Match %s", string));
+  if (!silc_regex_match(&reg, string, num_match, match, 0))
+    goto err;
+  for (i = 0; i < num_match; i++) {
+    if (match[i].start != -1) {
+      SILC_LOG_DEBUG(("Match start %d, end %d", match[i].start,
+                     match[i].end));
+      sub = silc_memdup(string + match[i].start, match[i].end - 
+                       match[i].start);
+      SILC_LOG_DEBUG(("Match substring '%s'", sub));
+      silc_free(sub);
+    }
+  }
+
+  silc_regex_free(&reg);
+
   regex = "foo[0-9]*";
   SILC_LOG_DEBUG(("Regex %s", regex));
   if (!silc_regex_compile(&reg, regex, 0))