我有一个多行字符串,每行末尾都有空格:
console.log(`*Env:*
*Brand:* `.replace("*Env:* ", "bla"));
只返回原始字符串
如何用尾随空格替换子字符串?
如果要搜索字符串中是否有多个空格,则需要使用regex。
const regex = / **Env* */
// this regex will search for *Env* in any line with trailing spaces either in left or right
console.log(` *Env:*
*Brand:* `.replace(regex, "bla"));