jquery - javascript replace string individual -
the example
red color or black color if replace or string and using code
var k = "red color or black color"; var s = k.replace("or","and"); alert(s); the result : red coland , black coland
i want replace or ..
if want replace insensitively, make use of regex , use ignorecase(i) flag use word-boundaries. string version replaces first occurrence , case-sensitive.
if want replace "or" regardless of case, add g regex.
var k = "red color or black color"; var s = k.replace(/\bor\b/gi,"and"); alert(s);
Comments
Post a Comment