hankknight
asked on
JavaScript: Case Insensitive Replace
How can I make this case insensitive?
var text = 'Hello World';
var r = 'World';
alert( text.replace(r,'EARTH') )
You could convert to uppercase first...
alert( text.toUpperCase().replace(r.toUpperCase(),'EARTH)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I was missing a closing quote and closing paren :
Here is udpated code
Here is udpated code
alert( text.toUpperCase().replace(r.toUpperCase(),'EARTH'));
ASKER
//Thanks leakim971
var text = 'Hello World';
var r = 'World';
alert( text.replace(new RegExp(r,"i"),'EARTH') )
please try the last example from this page
http://www.w3schools.com/jsref/jsref_replace.asp
HTH
Rainer