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

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -