The code is as follows, the purpose is to replace the emoticon string with a picture
EmojiParser.parse('Hahahahaha (normal) Hahaha (surprise)');
In this way, only the first one (normal) can be replaced, and the second one cannot be replaced. How to modify it?
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
});
}
}
/((.*))/
can be replaced by/((.*))/g
.g
stands for global global replacement.