前端之家收集整理的这篇文章主要介绍了
正则表达式实例(c语言),
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
- #include <stdio.h>
- #include <sys/types.h>
- #include <regex.h>
-
- int main(int argc,char**argv)
- {
- int status;
- int i;
- int cflags = REG_EXTENDED;
- regmatch_t pmatch[1];
- const size_t nmatch =1 ;
- regex_t reg;
- const char * pattern="^[A-Z]{2}\\w+@\\w{6}_\\w+.\\w+$";
- //const char * pattern="^[A-Z]{2}\\w+$";
- //const char * pattern="^\\w$";
-
- regcomp(®,pattern,cflags);
- status=regexec(®,argv[1],nmatch,pmatch,0);
- printf("%s",argv[1]);
- if(status == REG_NOMATCH)
- printf("no Match\n");
- else if(status ==0)
- {
- printf("match\n");
- }
- }
匹配AA1111@111111_0.0格式的字符串