代码如下,目的是将表情字符串替换成图片EmojiParser.parse('哈哈哈哈哈(normal)哈哈哈(surprise)');这样只能替换第一个(normal),第二个无法替换,请问怎么修改?export default class EmojiParser { static emojiSeries =[{ id: 101, name: 'normal' }, { id: 102, name: 'surprise' }]; static parse(content) { return content.replace(/(\(.*\))/, (match) => { let replaceStr = ''; for (const series of EmojiParser.emojiSeries) { if (match === `(${series.name})`) { replaceStr += `<img width="28" height="28" src="https://source.pixiv.net/common/images/emoji/${series.id}.png" />`; } } return replaceStr === '' ? match : replaceStr }); }}
添加回答
举报
0/150
提交
取消