2011-07-08 28 views
0

我知道你可以做這樣的事情:JavaScript的問題與string.replace

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

,你會得到如下:蘋果有任何科技公司的最大的資本儲備。蘋果公司位於加州。

如何使用全局不區分大小寫將07/08/2011等字符串更改爲07082011?

我嘗試了str.replace(/// gi,「」)的變體,但沒有運氣。

回答

2

試試這個:

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

嘗試使用轉義字符(反斜線):

str.replace(/\//gi, "") 
0
str = str.replace(/\//g,'') 

這將刪除所有正斜槓

+0

是不必要的 「我」在這種情況下。 –

+0

是的,你是對的,更新。 – psynnott