Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JavaScript: Case Insensitive Replace

Posted on 2013-05-14
5
Medium Priority
?
319 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

598 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