Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
why this function writes 2 instances of "on "?
(function myFunction()
{
var str="on";
var n=str.match(/^(on|off)$/i);
document.write(n);
})()
this is #javascript of course
even exec does the same
it should write "on" not "on,on"
2 Answers
- Anonymous8 years agoFavorite Answer
It's because your regex has the paretheses (). The first element of the array is the whole regex match, and the next elements represent the part that is matched inside parentheses.
- StevenLv 48 years ago
wouldn't you want to use str.length? I guess I'm assuming you want to count the letters in the string