title: Positive/Negative lookahead with grep and perl
body: <p>my login.txt file contains following entries</p>
  
  <pre><code>abc def
  abc 123
  def abc
  abc de
  tha ewe
  </code></pre>
  
  <p>when i do the positive lookahead using perl, i'm getting the following result</p>
  
  <pre><code>cat login.txt | perl -ne 'print if /(?)abc\s(?=def)/'
  abc def
  </code></pre>
  
  <p>when i use grep i'm getting the following result</p>
  
  <pre><code>cat login.txt | grep -P '(?&lt;=abc)\s(?=def)'
  abc def
  </code></pre>
  
  <p>negative lookahed results as follows from perl and grep.</p>
  
  <pre><code> cat login | perl -ne 'print if /(?)abc\s(?!def)/'
  abc 123
  def abc
  abc de
  </code></pre>
  
  <p>grep  result</p>
  
  <pre><code>cat login.txt | grep -P '(?&lt;=abc)\s(?!def)'
  abc 123
  abc de
  </code></pre>
  
  <p>perl matched the def abc for the negative lookahead. but it shouldn't matched def abc, as i'm checking abc then def pattern. grep returning the correct result.</p>
  
  <p>is something missing in my perl pattern ?</p>