用js很简单:<script> var a = document.createElement("a"); a.href="http://www.baidu.com/42/wo.html"; alert("http://" + a.hostname); </script> 弹出:http://www.baidu.com
using System.Text.RegularExpressions; //引用命名空间string url = "http://www.baidu.com/42/wo.html"; Match m = Regex.Match(url, @"(http://)[\w\.]+[/]"); Response.Write(m.ToString());
Match match = Regex.Match(uri, @"((http(s)?://)?)+[\w-.]+[^/]");//, RegexOptions.IgnoreCase domainName = match.Value;
var a = document.createElement("a");
a.href="http://www.baidu.com/42/wo.html";
alert("http://" + a.hostname);
</script>
弹出:http://www.baidu.com
using System.Text.RegularExpressions; //引用命名空间string url = "http://www.baidu.com/42/wo.html";
Match m = Regex.Match(url, @"(http://)[\w\.]+[/]");
Response.Write(m.ToString());
domainName = match.Value;