Safe replace {{some_var}} in JS strings


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.