Я хочу сопоставить каждую вещь между двумя словами GET и HTTP. Я перепробовал все, что знаю. Но это не работает. Любая помощь приветствуется. Шаблон GET. * HTTP должен соответствовать GET. Www.google.com HTTP.
Вот код
Заголовки:
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Main:
int main(int argc, char *argv[]) {
regex_t regex;
int reti;
char msgbuf[100];
regmatch_t pmatch[1];
/* Compile regular expression */
reti = regcomp(®ex, "GET.*HTTP", REG_EXTENDED);
if (reti) {
fprintf(stderr, "Could not compile regex\n");
exit(1);
}
/* Execute regular expression */
reti = regexec(®ex, argv[1], 1, pmatch, 0);
if (!reti) {
puts("Match");
char *match = strndup(argv[1] + pmatch[0].rm_so, pmatch[0].rm_eo - pmatch[0].rm_so);
printf("%s\n",match);
} else if (reti == REG_NOMATCH) {
puts("No match");
} else {
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
exit(1);
}
/* Free compiled regular expression if you want to use the regex_t again */
regfree(®ex);
return 0;
}
Есть ли что-то, что я делаю здесь не так.