我正在尝试修改一个名为 ReChat 的插件,以便它支持除默认表情之外的其他表情。
我需要制作这个正则表达式来替换整个单词我知道你需要添加\b
元字符但我不能让它工作。
例如,如果有两个带有名称的表情符号,emotICON
它将emotI
始终显示emotI
.
这是装载机:
ReChat.Playback.prototype._loadEmoticons = function() {
var that = this;
this._emoticons = [];
ReChat.get('https://api.twitch.tv/kraken/chat/emoticons', {}, function(result) {
$.each(result.emoticons, function(i, emoticon) {
var image = emoticon.images[0];
if (image.emoticon_set === 27) {
that._emoticons.push({
regex: new RegExp(emoticon.regex, 'g'),
code: $('<span>').addClass('emoticon').css({ 'background-image': 'url(' + image.url + ')', 'height': image.height, 'width': image.width }).prop('outerHTML').replace(/"/g, "'")
});
}
});
});
};
这是替代品:
ReChat.Playback.prototype._replaceEmoticons = function(text) {
$.each(this._emoticons, function(i, emoticon) {
text = text.replace(emoticon.regex, emoticon.code);
});
return text;
}
如果您需要完整的源代码,请访问https://github.com/pencil/rechat。