正则表达式实例(c语言)

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

猜你在找的正则表达式相关文章