title: Using preg_match to find which group is being replaced by preg_replace in php
body: <p>I am using preg_replace to find 2 corresponding words and then switching their places. I want to check that if the two corresponding words are:</p>
  
  <pre><code>&lt;span style="color: green;"&gt; &lt;/span&gt;,
  </code></pre>
  
  <p>then the while loop should not work. I have tried many patterns but can't write the correct one. The one that I have used is:</p>
  
  <pre><code>if(!preg_match ('~&lt;span style="color: green;"&gt;&lt;/span&gt;~', $myinput))
  </code></pre>
  
  <p>but it is not working in the way I want. You can view my complete code here in this link: <a href="http://sandbox.onlinephpfunctions.com/code/bf21f671ef7fcaaabad063fe235383550df0a59e" rel="nofollow">http://sandbox.onlinephpfunctions.com/code/bf21f671ef7fcaaabad063fe235383550df0a59e</a></p>