DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Count Email Address

02.09.2006
| 313 views |
  • submit to reddit
        // description of your code here

/*
  flex count.l; cc lex.yy.c -lfl -o count
*/
%{
int num_lines = 0, num_addr = 0;
%}

%%
\n    ++num_lines;
[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,} {
   ++num_addr;
}
.     ;
%%

main() {
   yylex();
   printf( "# of lines = %d, # of addresses = %d\n",
   num_lines, num_addr);
   return 0;
}

/* EOF */