Pergunta

I need to use regexp for matching and the code below works fine. However, I need to KEEP the dollar sign ($) as a true dollar sign and not a special character.

I've tried excluding but nothing is working.

IE:  [^$]

Here's the code. It works as expected except when the text contains a $ or IS the $.

textNode = "$19,000"; 
regex = RegExp("$19,000",'ig');
text = '$';

textReplacerFunc: function (textNode, regex, text) {
        var sTag = '<span class="highlight">';
        var eTag = '</span>';
        var re = '(?![^<>]*>)(' + text + '(?!#8212;))';
        var regExp = new RegExp(re, 'ig');
        textNode.data = textNode.data.replace(regExp, sTag + '$1' + eTag);
    },

RESULT: $ not highlighted. desired results: $19,000

Foi útil?

Solução

Make sure to double escape the $ as in :

text = '\\$';

Since you are using construction of RegExp instance using a string here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top