我没有使用C的经验,我需要使用PCRE来获得匹配.
这是我的源代码示例:
int test2()
{
const char *error;
int erroffset;
pcre *re;
int rc;
int i;
int ovector[OVECCOUNT];
char *regex = "From:([^@]+)@([^\r]+)";
char str[] = "From:regular.expressions@example.com\r\n"\
"From:exddd@43434.com\r\n"\
"From:7853456@exgem.com\r\n";
re = pcre_compile (
regex, /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
0); /* use default character tables */
if (!re) {
printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);
return -1;
}
rc = pcre_exec (
re, /* …Run Code Online (Sandbox Code Playgroud)