I'm playing with a some regular expressions and, while looking at some of my matches, I became curious as to why a the exec function produced as many results as it did.
I'm simply seeking a little clarification on the inner workings of the operation so that I can feel more comfortable with why a regular expression is returning n results, instead of just accepting that it does.
Ex.
var invalidValues = new RegExp(
"\\bZIP or City & State$|" +
"\\bCity & State or ZIP$|" +
"\\bEm[ai][ia]l Address(\\s\\(Optional\\)|$)|" +
"^$", "gi");
invalidValues.exec("Zip or City & State");
//returns ["Zip or City & State", undefined]
In the example above, I get why it's matching "Zip or City & State", but I don't know why a second match is being produced with an undefined value.
Thanks in advance.