#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <regex.h>
int main()
{
int cflags = REG_EXTENDED;
regmatch_t pmatch[1];
const size_t nmatch = 1;
int status, i;
regex_t reg;
char *pattern = "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$";
char *buf = "192.168.1.1";
regcomp(®, pattern, cflags);
status = regexec(®, buf, nmatch, pmatch, 0);
if (status == REG_NOMATCH)
printf("No Match\n");
else if(status == 0)
{
printf("Match!\n");
}
regfree(®);
return 0;
}
linux c ip过滤 正则表达式 初步代码
最新推荐文章于 2024-03-26 18:58:42 发布