#include <stdio.h>
#include <string.h>
#include <pcre.h>
int main(int argc, char **argv)
{
const char *error;
int erroffset;
int ovector[186];
char re[8192]="";
char txt[]="Dec 21 2012 23941 6745 9145072 01567 5511 23345 614567 123456 Ol\";";
char re1[]=".*?"; // Non-greedy match on filler
strcat(re,re1);
char re2[]="\\d+"; // Uninteresting: int
strcat(re,re2);
char re3[]=".*?"; // Non-greedy match on filler
strcat(re,re3);
char re4[]="\\d+"; // Uninteresting: int
strcat(re,re4);
char re5[]=".*?"; // Non-greedy match on filler
strcat(re,re5);
char re6[]="(\\d+)"; // Integer Number 1
strcat(re,re6);
char re7[]="(\\s+)"; // White Space 1
strcat(re,re7);
char re8[]="(\\d+)"; // Integer Number 2
strcat(re,re8);
char re9[]="(\\s+)"; // White Space 2
strcat(re,re9);
char re10[]="(\\d+)"; // Integer Number 3
strcat(re,re10);
char re11[]="(\\s+)"; // White Space 3
strcat(re,re11);
char re12[]="(\\d+)"; // Integer Number 4
strcat(re,re12);
char re13[]="(\\s+)"; // White Space 4
strcat(re,re13);
char re14[]="(\\d+)"; // Integer Number 5
strcat(re,re14);
char re15[]="(\\s+)"; // White Space 5
strcat(re,re15);
strcat(re,re16);
char re17[]="(\\s+)"; // White Space 6
strcat(re,re17);
char re18[]="(\\d+)"; // Integer Number 7
strcat(re,re18);
char re19[]=".*?"; // Non-greedy match on filler
strcat(re,re19);
char re20[]="(\\d+)"; // Integer Number 8
strcat(re,re20);
pcre *r = pcre_compile(re, PCRE_CASELESS|PCRE_DOTALL, &error, &erroffset, NULL);
int rc = pcre_exec(r, NULL, txt, strlen(txt), 0, 0, ovector, 186);
if (rc>0)
{
char int1[1024];
pcre_copy_substring(txt, ovector, rc,1,int1, 1024);
printf("(%s)",int1);
char ws1[1024];
pcre_copy_substring(txt, ovector, rc,2,ws1, 1024);
printf("(%s)",ws1);
char int2[1024];
pcre_copy_substring(txt, ovector, rc,3,int2, 1024);
printf("(%s)",int2);
char ws2[1024];
pcre_copy_substring(txt, ovector, rc,4,ws2, 1024);
printf("(%s)",ws2);
char int3[1024];
pcre_copy_substring(txt, ovector, rc,5,int3, 1024);
printf("(%s)",int3);
char ws3[1024];
pcre_copy_substring(txt, ovector, rc,6,ws3, 1024);
printf("(%s)",ws3);
char int4[1024];
pcre_copy_substring(txt, ovector, rc,7,int4, 1024);
printf("(%s)",int4);
char ws4[1024];
pcre_copy_substring(txt, ovector, rc,8,ws4, 1024);
printf("(%s)",ws4);
char int5[1024];
pcre_copy_substring(txt, ovector, rc,9,int5, 1024);
printf("(%s)",int5);
char ws5[1024];
pcre_copy_substring(txt, ovector, rc,10,ws5, 1024);
printf("(%s)",ws5);
char int6[1024];
pcre_copy_substring(txt, ovector, rc,11,int6, 1024);
printf("(%s)",int6);
char ws6[1024];
pcre_copy_substring(txt, ovector, rc,12,ws6, 1024);
printf("(%s)",ws6);
char int7[1024];
pcre_copy_substring(txt, ovector, rc,13,int7, 1024);
printf("(%s)",int7);
char int8[1024];
pcre_copy_substring(txt, ovector, rc,14,int8, 1024);
printf("(%s)",int8);
puts("\n");
}
}
从下次开始使用http://txt2re.com
你也可以制作一个简单的正则表达式字符串。为此,您只能将它们写在 1 个字符变量中。