Q:

indexOf for multiple options

Let say, I get the following using var content = this.innerHTML:
w here&nbsp;</div>

Using indexOf (or other ways), I want to check for the first position that has either "Space", "<" or "&nbsp".
In this case, it will be 1 (after "w").
What I am confused about is how do I check for the very first position that has either one of these three choices? Do I use Do...while to check for individual "options"?

A:

You're probably looking for a Regular Expression (Regex) and the String#search method. Regex is a bit much to learn all at once, but I'll explain this example code.
You can use square brackets to denote a set of characters, so for example [ <] says "match either a space or a less-than sign."
You can use the pipe | to separate possibilities if you want to match one pattern or another, and that's how to account for matching a non-breaking space HTML entity.

var string = 'w here&nbsp;</div>',
    index = string.search(/[ <]|&nbsp;/)
console.log(index) //=> 1

