Posted By

funkadelicsoul on 07/27/09


Tagged

regex highlighting


Versions (?)

Regular Expression Wrap


 / Published in: JavaScript
 

  1. var term = 'Valves';
  2. var value = 'Foo Foo Valves Blah Yo Yo';
  3.  
  4. var regex = new RegExp(term,'ig');
  5.  
  6. var replaced = value.replace(regex,'<span>$&</span>');
  7.  
  8. alert(replaced); //Foo Foo <span>Valves</span> Blah Yo Yo

Report this snippet  

You need to login to post a comment.