”js Javascript 字符串数组正则分割 字符串正则分割 “

时间:2020-11-30 09:03:54


<pre name="code" class="javascript">
/*
[------ js Javascript 字符串数组正则分割 字符串正则分割---------]
author:*** 2014/10/15
参数解释;
regexStr:正则表达式字符串;
separator:分割标志;
string:待分割验证的字符串;
如果需要对一个字符串数组进行分割正则,可先转为字符串。
例:
var regxStr=<span style="font-family: Arial, Helvetica, sans-serif;">'/^.*$/';</span>
var demo=calculateSize(regxStr,',','d,ssss');
<pre name="code" class="javascript">

for(var i=0;i<demo.length;i++){
alert(demo[i]);
};
<span style="white-space:pre"> </span><pre name="code" class="javascript">
<span> </span>


*/
//首先来个数组去重函数
Array.prototype.unique= function(){
var res = [];
var json = {};
for(var i = 0; i < this.length; i++){
if(!json[this[i]]){
res.push(this[i]);
json[this[i]] = 1;
}
}
return res;
}
//字符串根据标志正则分割
function stringSplitRegex(regxStr,separator,string){
var strArray=[];
var arries={};
var right=[];
var regx=new RegExp(regxStr);
strArray[strArray.length]=string;
for(var size=0;size<strArray.length;size++){
var str=strArray[size];
arries[size]=str.split(separator);
}
for(var key in arries){
var array=arries[key];
for(var arraySize=0;arraySize<array.length;arraySize++){
if(regx.test(array[arraySize]))
right[right.length]=array[arraySize];
}
}
return right.unique();
}