JavaScript正则例子

查看页面是否有某个js
var slist=document.getElementsByTagName('script') || [];
var reg=/jQuery\.min\.js/i;
for(var i=0;i<slist.length;i++){
if(reg.test(slist[i].src)){
return;
}
}
最简单的正则表达式,将匹配"jQuery.min.js"这个字符串
“i”表示不分大小写,i标志(i是ignoreCase或case-insensitive的表示)  

document.URL.match(/[^:]+/)
[]匹配指定范围内的任意字符,在[]里它表示一个负字符集,
匹配任何不在指定范围内的任意字符,这里将匹配除':'的所有字符 
+号表示字符至少要出现1次
match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。
stringObject.match(searchvalue)
stringObject.match(regexp)
(function(){
        console.info(document.URL)
        var r =document.URL.match(/[^:]+/);
        console.info(r);
        var rs =document.URL.match(/[^:]+/g);
        console.info(rs);
    })();
http://localhost:63342/cquery/jsFunctionTest/match.html
["http"]
["http", "//localhost", "63342/cquery/jsFunctionTest/match.html"]

 

 

posted @ 2015-11-27 14:06  ElenaSun娇娃的逆袭  阅读(145)  评论(0编辑  收藏  举报