title: c regexp and negative look ahead
body: <p>I've a string such this:  </p>
  
  <p><code>"result is abcdefg hij!klm &lt;/td"</code>  ( or everything else instead of abcd... )  </p>
  
  <p>The regex I've made is:<br>
  <code>"result is ([^&lt;]+) &lt;/td"</code>  </p>
  
  <p>This works well since a result is found. But when the string is:<br>
  <code>"result is not found &lt;/td"</code><br>
  ...how can I avoid extracting the words "not found"?  </p>
  
  <p>I known that there is negative look-ahead expression but these don't work in regex.h in C99.  </p>
  
  <ul>
  <li><code>"(?!not found)"</code> -> bad regex   </li>
  <li><code>"([^n][^o][^t][^ ][^f]..)"</code> -> doesn't match "now", for example   </li>
  <li><code>"(([^&lt;]+)&amp;(!not found))"</code> -> bad
  regex</li>
  </ul>
  
  <p>(there is no '&amp;' operator, I think that a solution can be: <code>a&amp;&amp;b == !a||!b</code> )  </p>
  
  <p>--EDIT--<br>
  Here you are the part of code that compute the regex.  </p>
  
  <pre><code>pmatch=malloc(nmatch*sizeof(regmatch_t));  
  
  printf("regex: %s\n",patrn);
  
  if (regcomp(&amp;rgT,patrn,REG_EXTENDED | REG_NEWLINE) != 0)
  {
      snprintf(globals.err_buff,MAX_BUFF,"bad regex: \"%s\"",patrn);
      w_report_error(globals.err_buff,__FILE__,__LINE__,__func__,0,0,error);
      return EXIT_FAILURE;
  }
  </code></pre>
  
  <p>-- EDIT --<br>
  maybe i found a solution:<br>
  my own regex function return the N'th backreference if passing it a number > 0 as parameter, so...<br>
  NOTE: <code>./regex</code> is only a C program that redirect argv[...] to the w_regexp of my own library.</p>
  
  <pre><code>$ ./regex "result is crack &lt;/td" 'result is (not found) &lt;/td|result is ([^&lt;]+) &lt;/td' 3
  regex: result is (not found) &lt;/td|result is ([^&lt;]+) &lt;/td
  "crack"
  ""
  "result is crack &lt;/td"
  $ ./regex "result is not found &lt;/td" 'result is (not found) &lt;/td|result is ([^&lt;]+) &lt;/td' 3
  regex: result is (not found) &lt;/td|result is ([^&lt;]+) &lt;/td
  ""
  "not found"
  "result is not found &lt;/td"  
  </code></pre>
  
  <p>so, i think that add a number to my struct which means the index of the backreference to use for extracting data can be a a solution, but i'll still waiting for a better way to this for another day, or 2.<br>
  thanks in advance.</p>
  
  <p>--EDIT-- ( too many times :) )<br>
  it works!
  i've put the string that i wanna avoid follower by '|' and the pattern for a correct string.<br>
  this is the regex:<br>
  <code>"result is not found &lt;/td|result is ([^&lt;]+) &lt;/td"</code><br>
  thanks again.</p>