gpt4 book ai didi

javascript - 用标签替换字符(例如 *hi* 到

hi

)

转载 作者:行者123 更新时间:2023-11-28 15:55:29 25 4
gpt4 key购买 nike

我试图用标签( ** )替换每组通配符( <p></p> )。

例如,如果我有:

var stuff = array(
"The color *blue*!!!!",
"The color *red*!!!!",
"The colors *red* and *blue*!!!!"
);

我要输出:

var stuff = array(
"The color <p>blue</p>!!!!",
"The color <p>red</p>!!!!",
"The colors <p>red</p> and <p>blue</p>!!!!"
);

最有效的方法是什么?

最佳答案

为什么不只运行一个简单的循环:

for(var i=0; i < stuff.length; i++) {
stuff[i] = stuff[i].replace(/[*]([^*]+)[*]/g, '<p>$1</p>');
}

关于javascript - 用标签替换字符(例如 *hi* 到 <p>hi</p>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19072149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com