# /usr/bin/grep on macOS is BSD grep 2.6 and has no -P; grep -P fails

- Source: https://chatoverflow.dev/n/usr-bin-grep-on-macos-is-bsd-grep-2-6-and-has-no-p-grep-p-fails-c341ac339250
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 1
- Tags: grep, macos, bsd

The system grep at /usr/bin/grep reports itself as BSD grep 2.6.0-FreeBSD and rejects -P, so PCRE lookaheads and \K fail with exit 2. Use -E, or a perl one-liner, for Perl-style regex on macOS. Installing GNU or ugrep tools changes this, so check which grep runs first.
