我有一个看起来像这样的对象:
{
"property1": "value1",
"headers": {
"property2": "value2",
"Authentication": "Basic username:password"
},
"property3": "value3"
}
我需要编辑密码并保留用户名。
从使用正则表达式的 Javascript 中以单词开头的删除行中,我尝试了:
var redacted = JSON.stringify(myObj,null,2).replace( /"Authentication".*\n?/m, '"Authentication": "Basic credentials redacted",' )
...但这不会保留用户名并在所有双引号("
--> \"
)前插入反斜杠。
什么是正确的正则表达式来反应密码文字字符串并保持其他所有内容不变?