<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>string and reg</title></head><body><script>/*一、知识点1. \ 将下一个字符标记为或特殊字符、或原义字符、或向后引用、或八进制转义符。例如, 'n' 匹配字符 'n'。'\n' 匹配换行符。序列 '\\' 匹配 "\",而 '\(' 则匹配 "("。2. ? 匹配前面的子表达式零次或一次,或指明一个非贪婪限定符。要匹配 ? 字符,请使用 \?。3. | 替换,"或"操作字符具有高于替换运算符的优先级,使得"m|food"匹配"m"或"food"。若要匹配"mood"或"food",请使用括号创建子表达式,从而产生"(m|f)ood"。4. g 执行全局匹配,而不是找到第一个匹配就停止.*/var mylocation = { 'protocol':'','hostname':'','pathname':'','query':''}var url = 'http://adtk.cn/index.html?key1=1&key2=2';var arr=url.split(/\:\/\/|\/|\?/g);var j=0;for(i in mylocation){ mylocation[i]=arr[j];j++;}console.log(mylocation);/*结果是:Object {protocol: "http", hostname: "adtk.cn", pathname: "index.html", query: "key1=1&key2=2"}hostname: "adtk.cn"pathname: "index.html"protocol: "http"query: "key1=1&key2=2"__proto__: Object*/</script></body></html> 分类: