harttle / harttle.github.io

Harttle Land 的源码和文章
https://harttle.land
Creative Commons Attribution 4.0 International
122 stars 32 forks source link

2016/02/23/javascript-regular-expressions #41

Open harttle opened 6 years ago

harttle commented 6 years ago

用正则表达式分析 URL - Harttle Land

http://harttle.land/2016/02/23/javascript-regular-expressions.html

harttle commented 6 years ago

分析的比较细,学习了。

By hieast 2016-06-20T05:55:40Z

harttle commented 6 years ago

同志你打错一个词
var parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
var url = "http://harttle.com:80/tags.html?simple=true#HTML",
result = parse_url.exec(url);
blanks = ' ';
fields = ['url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'];
fields.forEach(function(filed, i){
console.log(field + ':' + blanks.substr(field.length) + result[i]);
});

fields.forEach(function(field)) 这里应该是field才对~

By Scar Qin 2017-09-12T11:08:53Z

harttle commented 6 years ago

😀多谢指出

By Yang Jun 2017-09-13T02:10:23Z

harttle commented 6 years ago

写得很好~

By Scar Qin 2017-09-13T03:17:19Z