function regDir(str){
var reg=str
if(typeof reg=="string"){
reg=reg.replace(/[\[\]\\\^\:\.\?\+]/g,function(m){
return "\\"+m;
})
reg=reg.replace(/\*\*|\*/g,function(m){
if(m=="**"){
return "[\\w\\W]*";
}else{
return "[^\\\/]*";
}
})
reg=new RegExp(reg,"gi")
}
return reg
}
String.prototype.Test=function(regStr){
var reg=regDir(regStr)
return reg.test(this)
}
String.prototype.Replace=function(regStr,fn){
var reg=regDir(regStr)
return this.replace(reg,fn);
}
//是否符合
var str="http://www.baidu.com/b/da.js?n=21"
str=str.Replace("(http://**/*)?*",function(m,p1,p2){
console.log(p1)
return p1
})
str.Replace("http:/(/**/)*",function(m,p1,p2){
console.log(p1)
})