

./configure #进行配置 make make install
会看到,库文件将被安装至/usr/local目录下的bin/lib/include等目录下。然而./configure有更多选项,包括将库文件安装至其它目录下。从configure代码来看,是支持Aix的。
编译成功后,可将pcre.h拷入应用目录。
那么在使用了正则函数后,如何在buildclient编译呢。由于安装在/usr/local下,并非系统库目录,因而需设置LD_LIBRARY_PATH和LIB_PATH。开始时将其以-l 参数加在buildclient选项后,反复出错,后来才发现,-f 与-l ,指的是tuxedo库之前和之后,并非指定链接库的意思。因而在将libpcre.a拷入后,加以-f libpcre.a后,编译应用成功。当然这并非最好办法。在configure时将其安装入系统路径要方便许多。
正则函数使用:
int is_match (char *src, char *pattern)
{
pcre *re;
const char *error;
int erroffset;
int rc;
re = pcre_compile (pattern, /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
NULL); /* use default character tables */
/* Compilation failed: print the error message and exit */
if (re == NULL)
{
printf ("PCRE compilation failed at offset %d: %s\n", erroffset,
error);
return -1;
}
rc = pcre_exec (re, /* the compiled pattern */
NULL, /* no extra data - we didn't study the pattern */
src, /* the src string */
strlen (src), /* the length of the src */
0, /* start at offset 0 in the src */
0, /* default options */
NULL, 0);
/* If Matching failed: */
if (rc < 0)
{
free (re);
return -1;
}
free (re);
return rc;
}
调用:
char *mobileRex="^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\\d{8}$";
is_match(teleStr, mobileRex);
匹配,返回0,不匹配,返回-1。
buildclient参数:
buildclient [ -C ] [ -v ] [ {-r rmname | -w } ] [ -o name]
[ -f firstfiles] [ -l lastfiles]
原创文章,作者:苏葳,如需转载,请注明出处:https://www.swmemo.com/308.html
