title: Exclude the last character of a regex match
body: <p>I have the following regex: </p>
  
  
  
  <pre class="lang-none prettyprint-override"><code>%(?:\\.|[^%\\ ])*%([,;\\\s]) 
  </code></pre>
  
  <p>That works great but obviously it also highlights the next character to the last <code>%</code>.</p>
  
  <p>I was wondering how could I exclude it from the regex?</p>
  
  <p>For instance, if I have:</p>
  
  <pre class="lang-none prettyprint-override"><code>The files under users\%username%\desktop\ are:
  </code></pre>
  
  <p>It will highlight <code>%username%\</code> but I just want <code>%username%</code>. On the other hand, if I leave the regex like this: </p>
  
  <pre class="lang-none prettyprint-override"><code>%(?:\\.|[^%\\ ])*%
  </code></pre>
  
  <p>...then it will match this pattern that I don't want to: </p>
  
  <pre class="lang-none prettyprint-override"><code>%example1%example2%example3
  </code></pre>
  
  <p>Any idea how to exclude the last character in the match through a regex?</p>