不知对否

找到数组中匹配的单词,并且排序
此处对排序并不是很理解,暂且理解为完全匹配>前缀匹配>后缀匹配>包含匹配

var arr = ["ykit-config-yo","mykit","fekit","ykit-config-fekit","ykit","mykitcon"];
var n = arr.length;
var suffix = "ykit";
var reg1 = new RegExp(suffix);          //包含
var reg2 = new RegExp("^("+suffix+")");      //前缀
var reg3 = new RegExp("("+suffix+")$");      //后缀
var reg4 = new RegExp("^("+suffix+")$");  //完全
console.log(reg1);  //  /ykit/
console.log(reg2);  //  /^(ykit)/
console.log(reg3);  //  /(ykit)$/
console.log(reg4);  //  /^(ykit)$/

var result = [];  //完全匹配的数组
var pre = [];  //前缀数组
var next =[];  //后缀数组
var main = [];  //包含数组
for(var j=0;j

你可能感兴趣的:(不知对否)