replace all occurrence of a string - Javascript

replace all

Snippet Code


  
Rate this page :
  [ 0 votes]

Javascript replace() is used with regular expression "\g" in order to replace all the occurrences of a string.

var txt = 'scripts,javascripts,php'; //Replaces all occurences of a string var matches = txt.match(/,/g,"*"); result will be, scripts*javascripts*php

Tags


Ask Questions

Ask Question