2017-04-04 182 views
-1

過濾數據我有這樣的字符串:從字符串中刪除的特殊字符的jQuery

var str = "f2025%20%3D%20%2209%3A00%22%20and%20f5118288%20%3D%20%222017-03-31%22#"; 

如何刪除所有的特殊字符{ '%20%3D%20%22', '%3A' ,'%22%20','%20'}返回列表值,如下所示{'f2025','09','00','和','f5118288','2017-03-31 「}

回答

2

您可以使用以下正則表達式來分割使用此字符串

%20%3D%20%22|%3A|%22%20|%20|%22# 
var str = "f2025%20%3D%20%2209%3A00%22%20and%20f5118288%20%3D%20%222017-03-31%22#"; 
var strArray = str.split(/%20%3D%20%22|%3A|%22%20|%20|%22#/) 
+0

它爲我工作。非常感謝你!你救我一命 –

+1

不用擔心,考慮接受答案:) –

0

您可以使用replace特殊字符和split的慾望的結果。

var str = "f2025%20%3D%20%2209%3A00%22%20and%20f5118288%20%3D%20%222017-03-31%22#"; 
 
str = str.replace(/%20%3D%20%22/g, "@").replace(/%3D/g, "").replace(/%3A/g, "@").replace(/%22%20/g, "@").replace(/#/g, "").replace(/%20/g, "@").replace(/%22/g, "@"); 
 
var Result = str.split('@'); 
 
alert(Result);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

相關問題