使用 javascript 将文本文件中的多个字符串替换为一个字符串

Replace multiple strings in a text file with one string using javascript

我正在尝试使用 javascript

将文本文件中的多个字符串替换为一个字符串

我想将“user”和“password”这两个字符串替换为'replace the string' 有人帮我吗?

要添加到以前的回复中,您可以使用 capture groups 返回匹配文本的引用部分,即

如果您搜索“用户”

let newText = yourText.replace(/^((\"user\")(:".*")(.*))$/gm, '"removed"' );

如果您搜索“1232”

let newText = yourText.replace(/^((\".*\")(:"1232")(.*))$/gm, '"removed"' );