Got this regex string from “JavaScript: the good parts” (pp. 66). Can’t get it to work. Can anyone see what is wrong with it?
/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/
it’s supposed to split up a string like this:
https://stackoverflow.com/questions/ask
into constituents: scheme, slash, host, port, path, query, hash
btw: this regex needs to be generic… it’s going to be used on different “schemes”
Maybe this isn’t your goal, but why don’t you use
System.Uriclass?It has what you want and it parses raw URI/URL(s).
http://msdn.microsoft.com/en-us/library/system.uri.aspx