Posted By

gaunab on 03/16/07


Tagged

regex javascript replace String


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
korzhik


Javascript search and replace


 / Published in: JavaScript
 

Why doesn't this work?

  1. var str="foobar";
  2. var val="foo";
  3. var search='/'+val+'/i';
  4. alert(str.replace(search, '<strong>'+val+'</strong>'));
  5.  
  6. // it alerts "foobar" and not "<strong>foo</strong>bar"

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: seeal on December 29, 2009

return = foobar ???

You need to login to post a comment.