Skip to content

Instantly share code, notes, and snippets.

View VincentHelwig's full-sized avatar
🏠
Working from home

Vincent Helwig VincentHelwig

🏠
Working from home
View GitHub Profile
@VincentHelwig
VincentHelwig / gist:4548b388dc11b25eebfa
Last active August 29, 2015 14:08
Javascript Url Parsing with regexp
// FROM http://jsperf.com/url-parsing
var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/;
var url = "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content";
urlParseRE.exec(url);
0: "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content"
1: "http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread"
2: "http://jblas:password@mycompany.com:8080/mail/inbox"
3: "http://jblas:password@mycompany.com:8080"