title: pattern matching / extracting in c using regex.h
body: <p>I need help extracting a substring from a string using regex.h in C.
  In this example, I am trying to extract all occurrences of character 'e' from a string 'telephone'.  Unfortunately, I get stuck identifying the offsets of those characters.  I am listing code below:  </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;regex.h&gt;
  
  int main(void) {
      const int size=10;
      regex_t regex;
      regmatch_t matchStruct[size];
  
      char pattern[] = "(e)";
      char str[] = "telephone";
  
      int failure = regcomp(&amp;regex, pattern, REG_EXTENDED);
      if (failure) {
          printf("Cannot compile");
      }
  
      int matchFailure = regexec(&amp;regex, pattern, size, matchStruct, 0);
      if (!matchFailure) {
          printf("\nMatch!!");
      } else {
          printf("NO Match!!");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>So per GNU's manual, I should get all of the occurrences of 'e' when a character is parenthesized.  However, I always get only the first occurrence.  </p>
  
  <p>Essentially, I want to be able to see something like:</p>
  
  <pre><code>matchStruct[1].rm_so = 1;
  matchStruct[1].rm_so = 2;
  
  matchStruct[2].rm_so = 4;
  matchStruct[2].rm_so = 5;
  
  matchStruct[3].rm_so = 7;
  matchStruct[3].rm_so = 8;
  </code></pre>
  
  <p>or something along these lines. Any advice?</p>