0

I need to replace this string literally: /:)

However, if I do it like this

test = text.replace(//:\)/gi, replacement);

Javascript will treat // as the beginning of a comment. If I do it like this (add brackets):

test = text.replace(/(/:\))/gi, replacement);

this is a syntax error, since it will treat /(/ as the pattern

What can I do get around this?

Chin
  • 19,717
  • 37
  • 107
  • 164

1 Answers1

3

How about escaping the forward slash with a back slash also:

test = text.replace(/\/:\)/gi, replacement);
nickb
  • 59,313
  • 13
  • 108
  • 143
  • Oh right, silly me. I was looking at this http://stackoverflow.com/questions/5663987/how-to-properly-escape-characters-in-regexp and thought that `/` doesn't need to be escaped. Thanks! – Chin Dec 14 '13 at 19:27