title: How do I convert from using `grep -P` to `grep -E`?
body: <p>I have a script that we use on Ubuntu (Linux) and I'd like to convert it to be used on both Ubuntu (Linux) and MacOS X. <code>grep</code> on Linux is different than <code>grep</code> on FreeBSD (i.e. MacOS X); <code>grep</code> on MacOS X doesn't support the <code>-P</code> option. Unfortunately, using the <code>-E</code> option on both platforms doesn't give the same results. Consider the following code that works on Linux:</p>
  <pre class="lang-bash prettyprint-override"><code>wip_scenarios=$(grep -oP &quot;^\d+ scenarios?&quot; log/report.log | grep -oP &quot;\d+&quot;)
  echo &quot;\n&quot;
  echo $wip_scenarios
  </code></pre>
  <p>This returns a <code>0</code> on Linux. Replacing all the <code>-P</code> with <code>-E</code> makes this work on MacOS X, but on Linux, this just returns a <code>null</code> which doesn't help the rest of my script when I use conditionals like this:</p>
  <pre class="lang-bash prettyprint-override"><code>if [ $wip_scenarios != 0 ];then
  </code></pre>
  <p>One solution is to put a flag at the front and use the appropriate option set depending on the platform, but I was hoping for a cross-platform solution. Is there a way to do this?</p>