js正则将字符串中将br 替换为2格空格
可以使用正则表达式中的replace方法来替换字符串中的
为2个空格。以下是示例代码:
let str = "Hello<br>world<br><br>!";
let newStr = str.replace(/<br>/g, " ");
console.log(newStr); // 输出: "Hello world !"
在上面的代码中,我们使用正则表达式中的/g标志来匹配所有出现的
,然后使用replace方法将它们替换为2个空格。最后,将新字符串存储在变量newStr中,并输出它。
原文地址: https://www.cveoy.top/t/topic/hdsy 著作权归作者所有。请勿转载和采集!