#include <stdio.h> #include <string.h> #include <pcre.h> /********************************************************************** *#include <pcre.h> * *parameters: src: string * * pattern: regular expression * *return: match >= 0 and nomatch < 0 * *date: 2008-03-12 * *developer: Leon * **********************************************************************/ int fun_ismatch( char* src, char* pattern) { pcre *re; const char *error; int erroffset; int rc; if( (re = pcre_compile( pattern, 0, &error, &erroffset, NULL)) == NULL) goto bad; if( (rc = pcre_exec( re, NULL, src, strlen(src), 0)) < 0) goto bad; free(re); return rc; bad: free(re); return -1; } int main (int argc, char **argv) { struct timeval tpstart,tpend; const char *pattern = "^http://.+?btchina.net/download.PHP*"; argv[1] = "http://dl1.www2.btchina.net/download.PHP?s=1125f72b0f6f6887&attachmentid=1064643@http://bt3.btchina.net/"; gettimeofday( &tpstart, NULL); int result = fun_ismatch( argv[1], (char*)pattern); gettimeofday( &tpend, NULL); printf ("result: %d\nuse time: %u\n", result, tpend.tv_usec - tpstart.tv_usec); return; } |