木有讲解,直接上代码
#include<stdio.h>
#include<regex.h>
int main()
{
regex_t regex;
const size_t nmatch = 1;
char *buf = "sa612336@gmail.com";
const char *pattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*$";
int status, i;
int cflags = REG_EXTENDED;
regmatch_t pmatch[1];
regcomp(®ex, pattern, cflags);
status = regexec(®ex, buf, nmatch, pmatch, 0);
if(status == REG_NOMATCH)
{
printf("no match\n");
}
else if(status == 0)
{
printf("match\n");
for(i=pmatch[0].rm_so; i<pmatch[0].rm_eo; i++)
{
putchar(buf[i]);
}
printf("\n");
}
regfree(®ex);
return 0;
}The first regex
最新推荐文章于 2024-01-20 21:41:40 发布
本文提供了一段使用 C 语言实现的电子邮件地址验证代码。该代码利用正则表达式来判断输入的字符串是否符合电子邮件地址的标准格式。通过 regcomp 和 regexec 函数完成编译及匹配过程。
3628

被折叠的 条评论
为什么被折叠?



