title: R Regular Expression Lookbehind
body: <p>I have a vector filled with strings of the following format: <code>&lt;year1&gt;&lt;year2&gt;&lt;id1&gt;&lt;id2&gt;</code></p>
  
  <p>the first entries of the vector looks like this:</p>
  
  <pre><code>199719982001
  199719982002
  199719982003
  199719982003
  </code></pre>
  
  <p>For the first entry we have: year1 = 1997, year2 = 1998, id1 = 2, id2 = 001. </p>
  
  <p>I want to write a regular expression that pulls out year1, id1, and the digits of id2 that are not zero. So for the first entry the regex should output: 199721.</p>
  
  <p>I have tried doing this with the stringr package, and created the following regex:</p>
  
  <pre><code>"^\\d{4}|\\d{1}(?&lt;=\\d{3}$)"
  </code></pre>
  
  <p>to pull out year1 and id1, however when using the lookbehind i get a "invalid regular expression" error. This is a bit puzzling to me, can R not handle lookaheads and lookbehinds?</p>