Grep Command – Why BSD Grep Results Differ from GNU Grep

freebsdgreplinuxosxregular expression

My computer is running macOS 10.12.3 and I am using the system-installed grep utility with version 2.5.1-FreeBSD.

These are the outputs I get when testing various regexes:

Screenshot

But if I run these using GNU grep (version 2.25) I get the following:

Screenshot

GNU's grep looks correct to me and BSD's is incorrect, no? Why do they differ? I don't understand why BSD's grep is matching the "a" when the regex specifies that it must follow the beginning of the line.

Best Answer

I think this might be a bug in FreeBSD's grep. There's a bug report with similar issues.

Related Question