MSDN官方文件参考:https://msdn.microsoft.com/zh-cn/library/az24scfc.aspx
eg:
1.判断字符串是否是这样组成的,第一个必须是字母,后面可以是字母、数字、下划线,总长度为5-20
var reg = /^[a-zA-z]\w[4,19]/; (\w 视情况 更换 \s);
reg.test(str);
2.编写一个javascript的函数把url解析为与页面的javascript.location对象相似的实体对象,如:url
:'http://www.qq.com/index.html?key1=1&key2=2',最后输出的对象是
-
var mylocation = {
-
'protocol':'http',
-
'hostname':'',
-
'pathname':'',
-
'query':''
-
}
-
var url = 'http://www.qq.com/index.html?key1=1&key2=2';
-
var str=url.replace(/http\:\/\//,""); //过滤 http://
-
var a=str.split("/"); // 以“/”分割url 存入数组
-
mylocation.hostname=a[0];
-
var arr=a[1].split("?");
-
mylocation.pathname=arr[0];
-
mylocation.query=arr[1];
- console.log(mylocation);