Personally, I steal the HTParse.c
module from the W3C (it is used in the lynx Web browser, for instance). Then, you can do things like:
strncpy(hostname, HTParse(url, "", PARSE_HOST), size)
The important thing about using a well-established and debugged library is that you do not fall into the typical
traps of URL parsing (many regexps fail when the host is an IP address, for instance, specially an IPv6 one).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…