The regex object in javascript will remember where it left off when you use its' exec() method.

As a result, you cannot use it like you might expect to be able to in loops.

For instance, the following will not work the way you'd initially think it would

  for(x in classes) {
matches = myRegExp.exec(classes[x].trim());
if (matches === null) {
continue;
} else {
console.log(matches);
}
}
</pre>

The above will actually skip some of your elements in the match even if your understanding of regular expressions says otherwise.

The way to accomplish the above, and match all the terms, involves resetting the lastIndex property of the RegEx object. To quote regular-expressions.info,

"Calling the exec() function also changes the lastIndex property of the RegExp object. It stores the index in the subject string at which the next match attempt will begin. You can modify this value to change the starting position of the next call to exec()."</p>
So the correct way to do it is

  for(x in classes) {
myRegExp.lastIndex = 0;
matches = myRegExp.exec(classes[x].trim());
if (matches === null) {
continue;
} else {
console.log(matches);
}
}
</pre>

Where you include the reset of the lastIndex property.