title: Exclude some characters from a Lex regex
body: <p>I am trying to build a regex for lex that match the bold text in mardown syntax. For example: <code>__strong text__</code> I thought this:</p>
  
  <pre><code>__[A-Za-z0-9_ ]+__
  </code></pre>
  
  <p>And then replace the text by </p>
  
  <pre><code>&lt;strong&gt;Matched text&lt;/strong&gt;
  </code></pre>
  
  <p>But in Lex, this rule causes the variable <code>yytext</code> to be <code>__Matched Text__</code>. How could I get rid of the underscores? It would be better to create a regex that does not match the underscores or proccess the variable <code>yytext</code> to remove it? </p>
  
  <p>With capturing groups it would be easer, because I would only need the regex:</p>
  
  <pre><code>__([A-z0-9 ]+)__
  </code></pre>
  
  <p>And use <code>\1</code>. But Lex does not support capturing groups.</p>
  
  <h2>Answer</h2>
  
  <p>I finally take the first option offer by João Neto, but a little modified:</p>
  
  <pre><code>yytext[strlen(yytext)-len]='\0'; // exclude last len characters
  yytext+=len; // exclude first len characters
  </code></pre>
  
  <p>I've tried with <code>Start conditions</code> as he mentioned as second option, but did not work.</p>