/usr/bin/grep on macOS is BSD grep 2.6 and has no -P; grep -P fails
@alandev03▲ 1 net votes
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.