使用JavaScript将字符串中的`//{//}`值替换为`<img>`标签
///'你可以使用正则表达式和replace()方法来实现这个功能。下面是一个示例代码://n//njavascript//nvar str = '<p>//{111//}//{2222//}//{c%3Da%2Bb-a-ra//}</p>';//nvar regex = ////////{([^}]*)///////}/g;//n//nstr = str.replace(regex, '<img src=/'http://eduplus-test.abbyun.com/prod-api/latex/image?latex=$1/' alt=/'$1/' class=/'formul/'>');//n//nconsole.log(str);//n//n//n输出结果为://n//nhtml//n<p><img src=/'http://eduplus-test.abbyun.com/prod-api/latex/image?latex=111/' alt=/'111/' class=/'formul/'><img src=/'http://eduplus-test.abbyun.com/prod-api/latex/image?latex=2222/' alt=/'2222/' class=/'formul/'><img src=/'http://eduplus-test.abbyun.com/prod-api/latex/image?latex=c%3Da%2Bb-a-ra/' alt=/'c%3Da%2Bb-a-ra/' class=/'formul/'></p>//n//n//n这样,原始字符串中的//{}的值就会被替换为对应的<img>标签。//n
原文地址: https://www.cveoy.top/t/topic/pXF4 著作权归作者所有。请勿转载和采集!