?
Solved

JavaScript: Case Insensitive Replace

Posted on 2013-05-14
5
Medium Priority
?
314 Views
Last Modified: 2013-05-15
How can I make this case insensitive?

var text = 'Hello World';
var r = 'World';
alert( text.replace(r,'EARTH') )

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39166310
Hi,
please try the last example from this page

http://www.w3schools.com/jsref/jsref_replace.asp

HTH
Rainer
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39166323
You could convert to uppercase first...

alert( text.toUpperCase().replace(r.toUpperCase(),'EARTH)

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39166349
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39166435
I was missing a closing quote and closing paren :

Here is udpated code
alert( text.toUpperCase().replace(r.toUpperCase(),'EARTH'));

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 39167571
//Thanks leakim971
var text = 'Hello World';
var r = 'World';
alert( text.replace(new RegExp(r,"i"),'EARTH') )

Open in new window

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question