27

If your file contains

apples are good
apple cider is also good

Why would egrep '(?=apples)app' file fail to pick up any lines?

Using egrep 2.5.1 on MAC

tchrist
  • 78,834
  • 30
  • 123
  • 180
James Raitsev
  • 92,517
  • 154
  • 335
  • 470

1 Answers1

25

Extended regular expression doesn't have positive look-ahead feature. See the regex flavor comparison

Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
  • On mac OS, you can get GNU grep (which has PCRE support) through [homebrew-dupes](https://github.com/Homebrew/homebrew-dupes) – Jared Beck Apr 29 '14 at 20:33
  • 3
    The link above no longer seems to have a "regex flavor comparison". It is basically now just a site hawking the "Regex Buddy" program for $39.95. I think something like the flavor comparison is available here: http://www.greenend.org.uk/rjk/tech/regexp.html but it's astonishingly difficult to find information on this. – Steve Cohen Sep 18 '14 at 13:55
  • 10
    You can do this on Linux using the '-P' flag: **-P, --perl-regexp: Interpret PATTERN as a Perl regular expression. This is highly experimental and grep -P may warn of unimplemented features.** What's unusual is that the BSD version (Mac, Darwin, vis-a-vis year 2010) references '-P' tangentially at the bottom of the documentation but does not define it as a usable flag. Mac users can download a newer version of [Grep at the Gnu site](http://www.gnu.org/software/grep/). It's surprising that even OS X 10.9 is bundled with an old version with many bugs. – ingyhere Mar 10 '15 at 03:03
  • 3
    The grep on macOS is not an older GNU grep; it's just not GNU at all. So it doesn't have GNU extensions. – Mark Reed Apr 30 '17 at 11:36