php - regex to format operators in a expression
<p>I need to get all operators (arithmetic, comparison, logical...) in a string...</p>

<pre><code>((value+10)*10)&gt;=300   ||   (array[key]-20==0&amp;&amp;"foo==bar"!=="")
</code></pre>

<p>...and add a single whitespace before and after them (if doesn't already exists)...</p>

<pre><code>((value + 10) * 10) &gt;= 300 || (array[key] - 20 == 0 &amp;&amp; "foo==bar" !== "")
</code></pre>

<p>...ignoring what is between quotes or single quotes.</p>

<p>Aditional rules:</p>

<ul>
<li>add space only before pre-in/decrement operators </li>
<li>add space only after post-in/decrement operators </li>
</ul>

<p>Sounds easy but I can't get how I could do it using regex in PHP. Thanks if someone can help!</p>

<p>I'm trying to do something like <code>$str = preg_replace('(?&lt;=[\w\]\)\s\"\'])\!=(?=[\w\]\)\s\"\'])', ' != ', $str);</code> for every operator, but I don't think it's a good idea.</p>