Javascript string replace (all occurrences)


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



Copy this code and paste it in your HTML
  1. //replace all whitespaces with underscore
  2. string.replace(new RegExp(/\s/g), '_');
  3.  
  4. //replace the word 'replace' with 'replaced'
  5. string.replace(/replace/g, 'replaced');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.