title: How can I use lookbehind assertions in lex?
body: <p>I require positive lookbehind assertions in lex (flex 2.5.35). After investigating the documentation, I don't see a direct way to do this. It has something similar to a lookahead assertion (the r/s syntax), but not lookbehind. What's the best way to achieve the same effect?</p>
  
  <p>Here's an example: Say I have the folling rules in my scanner spec file:</p>
  
  <pre><code>a         printf("matched a ");
  b         printf("matched b ");
  c         printf("matched c ");
  d         printf("matched d ");
  </code></pre>
  
  <p>How would I match a 'd' following a 'b', and the 'b' itself, so that on an input of 'abd' I would get:</p>
  
  <pre><code>matched a matched b matched d following b
  </code></pre>
  
  <p>But for a string 'acd'</p>
  
  <pre><code>matched a matched c matched d
  </code></pre>
  
  <p>The rule:</p>
  
  <pre><code>bd        printf("matched d following b ");
  </code></pre>
  
  <p>obviously doesn't work since it consumes the b; for 'abd' it outputs:</p>
  
  <pre><code>matched a matched d following b
  </code></pre>
  
  <p>If I had pcre lookbehinds I could write:</p>
  
  <pre><code>(?&lt;=b)d   printf("matched d following b ");
  </code></pre>
  
  <p>and all would be well, but lex doesn't support this.</p>