路徑path的正則通配符-nodejs


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)
})

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM