title: Email validation in C using glibc regex.h
body: <p><strong>OK...got it to work with this regex:</strong></p>
  
  <pre><code>const char * reg_exp = "^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*@([a-z0-9])"
                         "(([a-z0-9-])*([a-z0-9]))+(.([a-z0-9])([-a-z0-9_-])?";
  </code></pre>
  
  <p>I don't yet how effective this expression is but I am happy to make some progress with this issue.</p>
  
  <hr>
  
  <p>New to C pattern matching (regex).  I believe that I have tried to find an answer to my problem.</p>
  
  <p>I am trying to get a simple email pattern matching to work in my registration module.  As I have it now coded, it fails to match a properly formatted email source on every pass.  I'm thinking, based on my very limited knowledge and understanding, that the following code should work if all other dependencies are met.  But, again, this just doesn't work.  Any help will be much appreciated.</p>
  
  <p>Updated Example Code:</p>
  
  <pre><code>#include &lt;regex.h&gt;
  
  regex_t regex;
  ... //other proc vars
  int r, e;
  unsigned char buf[RESBUF];
  char *source = "johnnydoe@cloudnine.com";
  
  const char *reg_exp1 = "/^[-a-z0-9~!$%^&amp;*_=+}{\'?]+(\.[-a-z0-9~!$%^&amp;*_=+}{\'?]+)*@"
                         "([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|"
                         "edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])"
                         "|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i";
  const char *reg_exp2 = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
  
  char proc[] = "create_user";
  
  r = regcomp(&amp;regex,reg_exp2,REG_EXTENDED);
  if(r) {
       sprintf(emessage,"REGEX COMPILE:Fail:%s:%s",proc,cgiRemoteAddr);
       log_proc(ebs-&gt;r,emessage,TXLOG);
       e = 1;
  }
  else {
       e = 0;
  }
  r = regexec(&amp;regex,source,0,NULL,0); // source email
  if(!r) {
       e = 0;
  }
  else
  if(r == 1) {
       sprintf(emessage,"REGEX MATCH:Fail:%s",proc);
       log_proc(ebs-&gt;r,emessage,TXLOG);
       e = 1;
  }
  else {
       regerror(r,&amp;regex,buf,100);
       sprintf(emessage,"REGEX MATCH:Fail:%s:%s",proc,buf);
       log_proc(ebs-&gt;r,emessage,TXLOG);
       e = 1;
  }
  regfree(&amp;regex);
  // Now evaluate e to determine success
  if (!e) { ... }
  </code></pre>