title: How can I use PCRE to get all match groups?
body: <p>I am inexperienced with using C, and I need to use PCRE to get matches.<br />
  Here is a sample of my source code:</p>
  
  <pre><code>int test2()
  {
      const char *error;
      int   erroffset;
      pcre *re;
      int   rc;
      int   i;
      int   ovector[OVECCOUNT];
  
      char *regex = "From:([^@]+)@([^\r]+)";
      char str[]  = "From:regular.expressions@example.com\r\n"\
                    "From:exddd@43434.com\r\n"\
                    "From:7853456@exgem.com\r\n";
  
      re = pcre_compile (
               regex,       /* the pattern */
               0,                    /* default options */
               &amp;error,               /* for error message */
               &amp;erroffset,           /* for error offset */
               0);                   /* use default character tables */
  
      if (!re) {
          printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);
          return -1;
      }
  
      rc = pcre_exec (
          re,                   /* the compiled pattern */
          0,                    /* no extra data - pattern was not studied */
          str,                  /* the string to match */
          strlen(str),          /* the length of the string */
          0,                    /* start at offset 0 in the subject */
          0,                    /* default options */
          ovector,              /* output vector for substring information */
          OVECCOUNT);           /* number of elements in the output vector */
  
      if (rc &lt; 0) {
          switch (rc) {
              case PCRE_ERROR_NOMATCH:
                  printf("String didn't match");
                  break;
  
              default:
                  printf("Error while matching: %d\n", rc);
                  break;
          }
          free(re);
          return -1;
      }
  
      for (i = 0; i &lt; rc; i++) {
          printf("%2d: %.*s\n", i, ovector[2*i+1] - ovector[2*i], str + ovector[2*i]);
      }
  }
  </code></pre>
  
  <p>In this demo, the output is only:</p>
  
  <p><code>0: From:regular.expressions@example.com</code><br />
   <code>1: regular.expressions</code><br />
   <code>2: example.com</code><br /></p>
  
  <p>I want to output all of the matches; how can I do that?</p>