title: Understanding lookahead in R regexp
body: <p>I'm trying to use multiple lookaheads to simulate an AND operator in R Perl-type regex with <code>grep</code>. However, I don't understand the output I am seeing. This is a sample code block</p>
  
  <pre><code>a &lt;- c("abcxyz", "abcdef", "defxyz", "abcdefxyz", "xyzdefabc")
  grep("(?&lt;=abc)(?=xyz)", a, ignore.case=TRUE, perl=TRUE)  # returns 1
  grep("(?=abc)(?=xyz)", a, ignore.case=TRUE, perl=TRUE)  # returns integer(0)
  </code></pre>
  
  <p>The second line suggests that the position in the string is between abc and xyz, and matches 'abcxyz'. Why does it not match 'abcdefxyz'?</p>
  
  <p>On the third line, I am trying to output 1, 4 and 5, but it returns not found. Why is this happening?</p>
  
  <p>I am using the alternative solution below but I would like to use lookaheads to deal with ordering when dealing with multiple lookaheads.</p>
  
  <pre><code>grep("abc.*xyz|xyz.*abc", a, ignore.case=TRUE, perl=TRUE)  # returns 1 4 5 as expected
  </code></pre>