Fiddle at http://jsfiddle.net/42zcL/
I have the following code, which should alert "No Match". If I put the regex into regexpal.com and run it, it doesn't match (as expected). With this code, it does match. I know there is another way to do it, which works correctly - /^((.*)Waiting(.*))?$/, but I am curious as to why this one fails. It should match a string with the text "Waiting" in it or nothing at all.
var teststring="Anything";
if (teststring.match(/^((.*)Waiting(.*))|()$/)) alert('match');
else alert('No Match');
EDIT: Clearer example:
var teststring="b";
if (teststring.match(/^(a)|()$/)) alert('match');
else alert('No Match');
Produces a Match, when I would expect "No Match"
Expected behaviour, as per regexpal.com:
teststring: a = match
teststring: b = no match
Actual behaviour in javascript:
teststring: a = match
teststring: b = match
^a|b$matches a string beginning withaor a string ending withb. You appear to be looking for^(a|b)$. (Or^(?:a|b)$.)teststring.indexOf("Waiting"), though?