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>
tags</p>
tags- whitespace/newlines
characters
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.
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?
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:
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.).
" foobar barfoo bar foo "
- pass" foobar barfoo bar food"
- fail" foobar barfo bar foo "
- fail