title: How do I test that a certain string ONLY contains certain types of HTML content in JavaScript regex?
body: <p>Long story short, I have a string in JavaScript that contains unknown HTML code. I want to test whether or not that string contains ONLY items from the following list:</p>
  
  <ul>
  <li><code>&lt;p&gt;</code> tags</li>
  <li><code>&lt;/p&gt;</code> tags</li>
  <li>whitespace/newlines</li>
  <li><code>&amp;nbsp;</code> characters</li>
  </ul>
  
  <p>If the string contains anything that is none of the above, I want false, if the string contains only the above (or nothing at all) I want true.</p>
  
  <p>The complicating factor is that I want this to work regardless of how many times those 4 elements show up or in what order. The only logical way I can think of to do it is to put them as non-capturing groups inside a character class, but I don't think that works. Is there another way to match an arbitrary combination of those 4 elements?</p>
  
  <p>EDIT: For those of you saying this shouldn't be done because I'm parsing HTML with regex, I can state it in a form that doesn't mention HTML:</p>
  
  <p>I have a string containing an unknown sequence of words and whitespace characters. I want to test if it does not contain any words that are not "foo", "bar", or some combination thereof ("foobar", "barfoofoobar", etc.).</p>
  
  <ul>
  <li><code>"  foobar barfoo bar    foo "</code> - pass</li>
  <li><code>"  foobar barfoo bar    food"</code> - fail</li>
  <li><code>"  foobar barfo  bar    foo "</code> - fail</li>
  </ul>