title: RegEx to match value of a variable or a string (with or without quotes)
body: <p>Here is my dilemma:</p>
  
  <p>I wrote this RegEx pattern which works in my sandbox but does not work on my website:</p>
  
  <p>Sandbox: <a href="http://regex101.com/r/vP3uG4" rel="nofollow">http://regex101.com/r/vP3uG4</a></p>
  
  <p>Pattern:</p>
  
  <pre><code>(.*[$]'.$variable.'\s*=\s*\'?)(.*?)(\'?;.*)
  </code></pre>
  
  <p>The line of code goes like this:</p>
  
  <pre><code>$savedsettings_new = preg_replace('/(.*[$]'.$variable.'\s*=\s*\'?)(.*?)(\'?;.*)/is','$1'. $value .'$3',$savedsettings_temp);
  </code></pre>
  
  <p>As you can see it works on the sandbox but it doesn't work live.</p>
  
  <p>I am trying to match values of variables that can be expressed as strings (with single quotes around them) or numerical values with no quotes, like so:</p>
  
  <pre><code>$match_string = 'value';
  $match_number = 1;
  </code></pre>
  
  <p>Right now this code works fine with strings but with numerical variables that are not enclosed in strings I just get the contents of the backreference $3 and I don't get anything at all before that!</p>
  
  <p>I'm scratching my head and really can't figure out why it works on RegEx101 but not live... Aren't I doing the right thing when matching for one or no single quotes (and escaping them because the preg_replace has quotes?</p>