javascript - What is the correct pattern to the text? -
i have string follows:
var str = "visit {inside string}";
i want replace {inside string} 'myschool'.
i tried doing below
var n = str.replace(/[{][^\s*][^\*}]/,'myschool');
but not working expected.
any pointer?
you can use
var n = str.replace(/\{[^}]*\}/,'myschool');
note if have more 1 replacement you'll have use g flag :
var n = str.replace(/\{[^}]*\}/g,'myschool');
Comments
Post a Comment