title: How to resolve unexpected token error with grep, regex, and PHP?
body: <p>I know REGEX well enough but am stuck on this one.  I am using PHP 5.4 to shell_exec() a grep statement with REGEX inside it to capture the SKU in a text file.  In php I don't see an error but the grep doesn't work.</p>
  <p>The goal is to capture the SKU in this text:</p>
  <pre><code>{'Product_Product_SKU':               'DOP36M94DPM'},
  </code></pre>
  <p>PHP Code:</p>
  <pre><code>$cmdSKU1 = 'grep -Po \'(?&lt;=\{\'Product_Product_SKU\':\s{15}\').+?(?=\'\}\,)\' '.$FileName;
  $chkSKU1 = trim(shell_exec($cmdSKU1));
  </code></pre>
  <p>Furthermore, when I look at the $cmdSKU1 variable in the debugger tool of the IDE I am using it's value is this as one line:</p>
  <pre><code>grep -Po '(?&lt;=\{'Product_Product_SKU':\s{15}').+?(?='\}\,)' /opt/web/default/RetailerParsing/RetailerDownload/MDD30TMSTH__20220113091043.htm
  </code></pre>
  <p>Furthermore some more, when I paste it into the Ubuntu console it gives me the error:</p>
  <pre><code>-bash: syntax eror near unexpected token `)'
  </code></pre>
  <p>Even if I go back and escape the exposed single quotes.  Infact, I escaped everything [^A-Za-z0-9] just to make sure! No beans.</p>
  <p>Lastly, if I try to double escape the single quotes within the REGEX in the PHP IDE I get a red squiggly underline error under the words <em>Produce_Product_SKU</em>.</p>