I have this regex in JavaScript:
var val = val.replace(/[":)"]/g, "<img src = \"/img/smile.png\" height = 24 width = 24>");
Basically, this regex should replace :) with an image of a smiley, however it is placing an image of a smiley face on either : or ) not when both are next to each other.
How must I adapt this regex: /[":)"]/g to only replace if there is an exact match for :) not just one on it’s own?
Thanks
What you have now is a character class, meaning it’s looking to match either a
",:, or)and replace it with the image.To fix this, your regex should be
/:\)/g: