我正在为CMS创建一个组件,它在文本输入的响应上运行一个查找/替换,它应该用
我已经成功地创建了一个简单的string.replace,它成功地替换了单个实例(我的regex完全匹配),但是,我需要一些帮助来重构重构以找到所有实例。
article.content = "this is an image, {html_image id=222}. This is also an image {html_image id=111}
article.content = article.content.replace(
new RegExp('{html_image id=222}'),
'<img src="" />'
);
current output = "this is an image, <img src="222"/>. This is also an image {html_image id=111}"
expected output = "this is an image, <img src="222"/>. This is also an image <img src="111"/"发布于 2020-02-13 11:07:21
您可以使用以下代码(使其适应您的变量):
var content = "this is an image, {html_image id=222}. This is also an image {html_image id=111}";
content = content.replace(
/{html_image id=(\d*)}/g,
'<img src="$1" />'
);
console.log(content);
https://stackoverflow.com/questions/60206197
复制相似问题