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
Post a Comment