我偶然发现了一个令我惊讶的事实。
console.log("asdf".replace(/.*/g, "x"));
Why two replacements? It seems any non-empty string without newlines will produce exactly two replacements for this pattern. Using a replacement function, I can see that the first replacement is for the entire string, and the second is for an empty string.