91JS native: node.js parsing rules for a URL

Built with node.js server environment, its built-in module URL can pass over the browser URL parsing, and make the appropriate response based on the analysis results. 
1, built-in module incorporated url node, using the parse method to parse module url winUrl
`` `JavaScript
var url = the require ( 'url');
var = winUrl url.parse ( 'http://www.zhu.cn:80 /ccc/index.html?name=zxt&age=26#33 ', to true);
the console.log (winUrl);
winUrl {
Protocol:' HTTP: ',
slashes: to true,
the auth: null,
Host:' www.zhu. CN: 80 ',
Port:' 80 ',
hostname:' www.zhu.cn ',
the hash:' # 33 is',
Search: '? name = & Age = 26 is ZXT',
Query: {name: 'ZXT', Age: '26'}, query true when the second line is absent: 'name = & Age = 26 is ZXT',
pathname: '/ccc/index.html',
path: '/ CCC / index.
the href: 'http://www.zhu.cn:80/index.html?name=zxt&age=26#33'}
`` `

. 4, packaging analysis method (Analytical value and the question mark HASH value parameter in the URL)
` ` JavaScript `: RUN
function queryURLParameter (URL) {
var obj = {};
var REG = / ([? ^ = & #] +) = ([? ^ = & #] +) / G;
url.replace (REG, function () {
obj [arguments [. 1]] = arguments [2];
});
REG = / # ([# & ^ =?] +) /;
IF (reg.test (URL)) {
obj [ 'the HASH '] = reg.exec (URL) [. 1];
}
return obj;
}
var str1 = "https://www.baidu.com/newspage/data/landingsuper?AAA=1111&BBB=222&CCC=333#1234";
var = queryURLParameter ABC1 (str1);
the console.log ( "1st output:", ABC1);

function Hasha (URL) {
REG = var / # ([# & ^ =?] +) /;
IF (reg.test (URL)) {
return reg.exec (URL) [. 1];
}
}
var str2 = "HTTPS: // WWW. baidu.com/newspage/data/landingsuper?AAA=1111&BBB=222&CCC=333#1234 "
var = Hasha ABC2 (str2);
the console.log (" 2nd output: "+ ABC2);

var ary = [" zero " , "one", "two", "three", "four", "five", "six", "seven", "eight" and "nine"];
var str3 = "year 2017";
var ABC3 str3.replace = (/ \ D / G, function () {
return ary [arguments [0]]
});
the console.log ( "third output:" + ABC3);

/ * output matching regular I [you friends] money into * /
var str4 = 'I <img src = "haha.png" alt = " your friend" /> money into';
(. +) var REG = / <(.+)t="(.+)"\/>(.+)/;
var AAA=reg.exec(str4);
var abc4=AAA[1]+"["+AAA[3]+"]"+AAA[4];
console.log("第4次输出:"+abc4);
```

Guess you like

Origin www.cnblogs.com/gushixianqiancheng/p/10967160.html