Q:

Javascript Regex object and the dollar symbol

In the code below. I expected true but i am getting false instead. What am I missing?
var text = "Sentence $confirmationlink$ fooo";     
alert(placeHolderExists(text,'confirmationlink'); // alerts false
function placeHolderExists(text,placeholdername) {  
  var pattern = new    RegExp('\$'+placeholdername+'\$');    
  return pattern.test(text);
}

A:

The "\" in the RegExp expression builder is treated as an escape character when building the string, just as it is in the actual RegExp. You need to escape twice, try:
new RegExp('\\$'+placeholdername+'\\$');

A:

Should be
function placeHolderExists(text,placeholdername) {  
  var pattern = new    RegExp('\\$'+placeholdername+'\\$');    
  return pattern.test(text);
}

You need to double escape your $ signs  
EDIT:
annakata explains why. 

A:

This confusion is another example of why you shouldn't use regex unless you really need to.
return text.indexOf('$'+placeholdername+'$')!=-1;

...is simpler, quicker, and doesn't fall over when you have funny characters in it.

