我有一个这样的字符串:
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',& #39;%20'}从上面的字符串返回列表值,如{' f2025',' 09',' 00',' ;和',' f5118288',' 2017-03-31'}
答案 0 :(得分: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#/)
答案 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>