title: Negating a backreference in Regular Expressions
body: <p>if a string has this predicted format:</p>
  
  <pre><code>value = "hello and good morning"
  </code></pre>
  
  <p>Where the " (quotations) might also be ' (single quote), and the closing char (' or ") will be the same as the opening one. I want to match the string between the quotation marks.</p>
  
  <pre><code>\bvalue\s*=\s*(["'])([^\1]*)\1
  </code></pre>
  
  <p>(the two \s are to allow any spaces near the = sign)</p>
  
  <p>The first "captured group" (inside the first pair of brackets) - 
  should match the opening quotation which should be either ' or "
  then - I'm supposed to allow any number of characters that are not what was captured in the first group, and then I expect the character captured in the group (the enclosing quotation marks).</p>
  
  <p>(the required string should be captured in the second capture-group). <br />
  This doesn't work though.</p>
  
  <p>This does:</p>
  
  <pre><code>\bvalue\s*=\s*(['"])([^"']*)["']
  </code></pre>
  
  <p>but I want to make sure that both the opening and closing quotation mark (either double or single) are the same.</p>
  
  <p><br />
  <strong>EDIT</strong> <br />
  The goal was basically to get the opening tag of an anchor that has a certain class-name included within its class attribute, and I wanted to cover the rare occasion of the class attribute including a (') or a (").</p>
  
  <p>Following all of the advices here, I used the pattern:</p>
  
  <pre><code>&lt;\s*\ba\b[^&lt;&gt;]+\bclass\s*=\s*("|'|\\"|\\')(?:(?!\1).)*\s*classname\s*(?:(?!\1).)*\1[^&gt;]*&gt;
  </code></pre>
  
  <p><em>Meaning</em>: <br />
  Find a tag-open sign. <br />
  Allow any spaces. <br />
  Find the <strong>word</strong> a. <br />
  Allow any non-closing-tag. <br />
  Find "class (any spaces) = (any spaces)" <br />
  Get opening quotes, one of the following: (" or ' or \" or \'). <br />
  From Alan Moore's answer: Allow any characters that are not the opening quotes. <br />
  find classname <br />
  Allow any characters that are not the opening quotes. <br />
  Find the closing quote which is the same as the opening. <br />
  Allow any unclosing-tag chars. <br />
  Find the closing tag char. <br /></p>