Made grep regex work on mac too.

Turns out grep does different things on Mac and Linux. This new regex is a bit more clumsy but works for both.

I should consider rewriting this as a python script since bash scripts are hard to get right.