@H_403_0@废话不多说了,直接给大家贴代码了,具体代码如下所示:
<div class="jb51code">
<pre class="brush:js;">
var msg="dsada[emoji:37]dsadas[emoji:3900]法拉綏芬河";
function fetch(msg) {
var match,result = msg,reg = /[emoji:\d+]/g,emojiIndex,totalEmojiNum = 45;
while (match = reg.exec(msg)) {
console.log(match[0]);//[emoji:37],[emoji:3900]
emojiIndex = match[0].slice(7,-1);
console.log(emojiIndex);//37,3900
if (emojiIndex > totalEmojiNum) {
result = result.replace(match[0],'[X]');
} else {
result = result.replace(match[0],'');
};
};
return result;//"dsadadsadas[X]法拉綏芬河"
}
fetch(msg);