You should either pass a string to the constructor for regexen, or use the regex literal syntax, but not both.
var bodyIDregex = /<body[^>]*id=["'](.*?)["']>/gi
or
var bodyIDregex = new RegExp("<body[^>]*id=["'](.*?)["']>","gi")
Update:
As you have correctly identified in your answer, the problem stems from the fact that the regex search continues from the position of the last character in the previous match. One way to correct this is to reset lastIndex
, but in this case this is not required, since you only need to match against the string once:
var bodyIDregex = /<body[^>]*id=["'](.*?)["']>/gi,
bodyID = bodyIDregex.exec(html);
//bodyID is now the array, ["<body id="test">asdf</body>", "test"]
alert(bodyID[1]);
//alerts the captured group, "test"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…