呼啦一阵风
像这样的:function setEnv(envText, key, value) { if (!envText) { return; } const rp = new RegExp(`${key}=(.*?)\\s`); let result = envText.replace(rp, (m, $1) => { return m.replace($1, value); }); if (!rp.test(result)) { result += `\n${key}=${value}`; } return result;}console.log( setEnv( `# I am a note ... key1=value1 key2=value2 # I am a note ...`, 'key1', 'value2', ),);但这不起作用:setEnv( `# I am a note ... key1=value1 key2=value2`, 'key2', 'value1', )setEnv( `# I am a note ... key1key2=value1 key2=value2`, 'key2', '2222', )