使用正则表达式替换javascript中的情感字符

Vim*_*tel 6 javascript regex jquery

我有以下JavaScript代码.

var emoticons = {
    ':)': '<span class="emoticon emoticon_smile"></span>',
    ':-)': '<span class="emoticon emoticon_smile"></span>',
    ':(': '<span class="emoticon emoticon_sad"></span>',
    ':d': '<span class="emoticon emoticon_bigSmile"></span>',
    ':D': '<span class="emoticon emoticon_bigSmile"></span>'
}
Run Code Online (Sandbox Code Playgroud)

现在要用给定文本中的span替换情感我正在使用以下函数

function Emotions (text) {
    if (text == null || text == undefined || text == "") return;
    var pattern = /[:\-)(D/pPy@'*]+/gi;
    return text.replace(pattern, function (match) {
        return typeof emoticons[match] != 'undefined' ?
           emoticons[match] :
           match;
    });
}
Run Code Online (Sandbox Code Playgroud)

现在上面的代码工作正常.如果我在函数中传递文本如下

Emotions("Hey this is a test :( :(");
Run Code Online (Sandbox Code Playgroud)

看到两种情绪之间的空间.但如果我删除两种情感之间的空间,那么它就不起作用.如下所示

Emotions("Hey this is a test :(:(");
Run Code Online (Sandbox Code Playgroud)

我的正则表达式有问题,但我无法弄明白.

hpa*_*lar 6

/:-?[()pPdD]/gi
Run Code Online (Sandbox Code Playgroud)

[]括号中的字符是posibilites并按顺序保留