function parseUrl1(data) {
var e=/^((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?$/;
if (data.match(e)) {
return {url: RegExp['$&'],
protocol: RegExp.$2,
host:RegExp.$3,
path:RegExp.$4,
file:RegExp.$6,
hash:RegExp.$7};
}
else {
return {url:"", protocol:"",host:"",path:"",file:"",hash:""};
}
}
function parseUrl2(data) { var e=/((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w-.]+.[^#?\s]+)(#[\w-]+)?/;
if (data.match(e)) {
return {url: RegExp['$&'],
protocol: RegExp.$2,
host:RegExp.$3,
path:RegExp.$4,
file:RegExp.$6,
hash:RegExp.$7};
}
else {
return {url:"", protocol:"",host:"",path:"",file:"",hash:""};
}
}
References :http://lawrence.ecorp.net/inet/samples/regexp-parse.php
No comments:
Post a Comment