Posted By

inreflection7 on 11/22/12


Tagged

js template your own roll


Versions (?)

Safe replace {{some_var}} in JS strings


 / Published in: JavaScript
 

For those moments of weakness when .replace() looks like a good idea...

  1. // Bad example but you get where I'm going with this.
  2.  
  3. my_string = "{{some_var}} weather out today";
  4.  
  5. my_string.replace(/\{\{(.+?)\}\}/g, 'great');

Report this snippet  

You need to login to post a comment.