First of all, str.replace("a","b")
only replaces the first occurrence in JavaScript. To replace all of them, you need to use a regex with g
modifier. So, you could try str.replace(/\n\t/g,"xxx")
first.
Next, why does it work in VSCode? In VSCode regex, \n
matches any line break sequence that is selected in the bottom right-hand corner of VSCode app. It works as \R
in PCRE, Java, Onigmo, etc. in this case.
As there can be many line ending sequences you may consider "converting" VSCode \n
to (?:\r\n|[\r\n\x0B\x0C\x85\u2028\u2029])
that matches any single Unicode line break sequence and use
s = s.replace(/(?:\r\n|[\r\n\x0B\x0C\x85\u2028\u2029])\t/g, '')