Possible Duplicate:
Why RegExp with global flag in Javascript give wrong results?
My code is as follows,
HTML:
<p id="test"></p>
JavaScript:
var patt = /h/gi;
var arr = ["", "2Hour", "4Hour", "8Hour", "Next Business Day"];
var test = document.getElementById("test");
for (var i = 0; i < arr.length; i++)
{
if (patt.test(arr[i])) {
test.innerHTML += " " + arr[i];
}
}
However, the output that get is 2Hour 8Hour
, why's 4Hour not a part of the output?
Is there something wrong with my regex? how can I solve this issue?
I've put it up on fiddle