Replace a word using javascript -


i want replace word between 2 "bla bla"

mean have sentence - he "bad boy". want replace "bad boy" good boy out ""

how dynamically using java script live example helpful.

code have tried

var str='he "bad boy".';  var n=str.match(""); 

var str='he "bad boy" , "bad boy".';  var n=str.replace(/\".*?\"/gi, 'good boy'); //g: globally, i: case-insensitive console.log(n) 

edit:

/\".*\"/ without ? match chars in quotes including ending code, match entire bad boy" , "bad boy since in quotes. trick use ? make match less greedy.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -