#include <stdio.h>
#include <sys/types.h>
#include <regex.h>
int main(){
char pattern[]="^..[A-Z]{2} [0-9]{4} ([0-9A-z]{6})$";
char match[]="TEST 1234 MARKUS";
size_t regex_nmatch=2;
regex_t regex;
regmatch_t regex_pmatch[regex_nmatch];
printf("checking: %s %s\n",match, pattern);
if (regcomp(®ex,pattern,REG_EXTENDED)==0&®exec(®ex,match,2,regex_pmatch,0)==0){
printf("%s\n",&match[regex_pmatch[1].rm_so]);
}
regfree(®ex);
} |