46
rated 0 times
[
49]
[
3]
/ answers: 1 / hits: 6643
/ 4 Years ago, fri, april 17, 2020, 12:00:00
I stumbled across a surprising (to me) fact.
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.
More From » regex