title: How to match strings that contain neither A nor B using Java Regex?
body: <p>I'm a newbie to Java regular expressions. My apologies if you find this question really simple..But I've seen some similar questions and tried those answers, neither worked.</p>
  
  <p>I'm trying to match strings that have a pattern 'Words outside parenthesis ( word )', There could be several choices for the stuff within the parenthesis, but I want to exclude some of them. In other words, strings that don't contain some words within the parenthesis should be matched.</p>
  
  <p>e.g. If I don't want A or B to be within the parenthesis, </p>
  
  <pre><code> words outside parenthesis ( C )  // should match
   words outside parenthesis ( A )  // should not match
   words outside parenthesis ( B )  // should not match
  </code></pre>
  
  <p>where A and B could be word or phrase. But they won't appear together (There is no way that the pattern 'AB' appears within the parenthesis).</p>
  
  <p>I've tried:</p>
  
  <pre><code>    .+\(\s*(?!A|B)\s*\)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    .+\(\s*^/(?!A|B)\s*\)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    .+\(\s*(?!\bA\b)(?!\bB\b)\s*\)
  </code></pre>
  
  <p>However, neither of them worked. Please help! Thanks!</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Maybe I didn't clarify myself. A or B could be word or phrase, which means A could be the word 'hello', B could be 'hello world' and I don't want 'hello' or 'hello world' to be matched. So [^AB] won't work for my case because that would become [^hellohello world].</p>