Return to Snippet

Revision: 2627
at March 16, 2007 06:28 by gaunab


Initial Code
var str="foobar"; 
var val="foo"; 
var search='/'+val+'/i'; 
alert(str.replace(search, '<strong>'+val+'</strong>'));

// it alerts "foobar" and not "<strong>foo</strong>bar"

Initial URL

                                

Initial Description
Why doesn't this work?

Initial Title
Javascript search and replace

Initial Tags
regex, javascript, replace

Initial Language
JavaScript