Created
November 1, 2014 05:58
-
-
Save clarkzjw/5244046565050a01624e to your computer and use it in GitHub Desktop.
regex in C/C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/types.h> | |
#include <regex.h> | |
int main(int argc,char** argv) | |
{ | |
int status,i; | |
int cflags=REG_EXTENDED; | |
regmatch_t pmatch[1]; | |
const size_t nmatch=1; | |
regex_t reg; | |
const char *pattern ="^\\w(\\.?\\w)+@\\w+(\\.\\w+)*\\.[A-Za-z]+$"; | |
char buf[256]; | |
regcomp(®, pattern,cflags); | |
while(scanf("%s", buf)!=EOF) | |
{ | |
if((status=regexec(®,buf,nmatch,pmatch,0))==0) | |
{ | |
printf("YES\n"); | |
regfree(®); | |
} | |
else | |
{ | |
printf("NO\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment