title: Regex - Modifying strings except in specified enclosures - PHP
body: <p>I have found similar answers to my current needs on SO, however I am still trying to grasp modifying strings based on a rule, except in certain enclosures within those strings.</p>
  
  <p>Example of what Im trying to accomplish now:</p>
  
  <pre><code>preg_replace("/\s*,\s*/", ",", $text)
  </code></pre>
  
  <p>I found the above in many places. It will remove spaces before and after all commas in a string.</p>
  
  <p>That works great. However, if I want to exclude modifying commas found within " ", I am not sure how that rule has to be modified.</p>
  
  <p>Any help? Thanks!</p>
  
  <p>EDIT: I want to clarify my question:
  I would like all whitespace before and after the commas in the following sentence removed, except commas found in double or single quotes:</p>
  
  <pre><code>a, b , c "d, e f g , " , h i j ,k lm,nop
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>a,b,c "d, e f g , ",h i j,k lm,nop
  </code></pre>