You can also expand the string object to support urlParts
Example
http://jsfiddle.net/stofke/Uwdha/
Javascript
String.prototype.urlParts = function() { var loc = this; loc = loc.split(/([a-z0-9_\-]{1,5}:\/\/)?(([a-z0-9_\-]{1,}):([a-z0-9_\-]{1,})\@)?((www\.)|([a-z0-9_\-]{1,}\.)+)?([a-z0-9_\-]{3,})((\.[az]{2,4})(:(\d{1,5}))?)(\/([a-z0-9_\-]{1,}\/)+)?([a-z0-9_\-]{1,})?(\.[az]{2,})?(\?)?(((\&)?[a-z0-9_\-]{1,}(\=[a-z0-9_\-]{1,})?)+)?/g); loc.href = this; loc.protocol = loc[1]; loc.user = loc[3]; loc.password = loc[4]; loc.subdomain = loc[5]; loc.domain = loc[8]; loc.domainextension = loc[10]; loc.port = loc[12]; loc.path = loc[13]; loc.file = loc[15]; loc.filetype = loc[16]; loc.query = loc[18]; loc.anchor = loc[22];
Application:
var link = "http://myusername: mypassword@test.asdf.com /a/b/c/index.php?test1=5&test2=789#tite"; var path = link.urlParts().path; var path = link.urlParts().user;
source share