PruitIgoe
PruitIgoe

Reputation: 6384

javascript string.replace question

I know you can do something like this:

var str = "Microsoft has the largest capital reserves of any tech company. Microsoft is located in California.";
str = str.replace(/microsoft/gi, "Apple");

and you'd get the following: Apple has the largest capital reserves of any tech company. Apple is located in California.

How can I use the global case insensitive to change a string like 07/08/2011 to 07082011?

I tried variations of str.replace(///gi, "") with no luck.

Upvotes: 0

Views: 68

Answers (3)

The Mask
The Mask

Reputation: 17427

Try this:

var input = "07/08/2011";
var output = input.replace(/\//g,""); //output 07082011

Upvotes: 2

psx
psx

Reputation: 4048

str = str.replace(/\//g,'')

this will remove all forward slashes

Upvotes: 0

Scherbius.com
Scherbius.com

Reputation: 3414

try using escape character (back slash):

str.replace(/\//gi, "")

Upvotes: 0

Related Questions