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

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

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

php - Cloud9 cloud IDE and CakePHP -