This snippet demonstrates how to extract the host/domain name from a valid URL using regular expressions.
using System.Text.RegularExpressions;
...
public static string ExtractDomainFromURL(string in_URL)
{
string regexPattern = @"^(?(?[^:/\?#]+):)?(?"
+ @"//(?[^/\?#]*))?(?[^\?#]*)"
+ @"(?\?(?[^#]*))?"
+ @"(?#(?.*))?";
Regex re = new Regex(regexPattern, RegexOptions.ExplicitCapture);
Match m = re.Match(in_URL);
return m.Groups["s1"].Value + m.Groups["a1"].Value;
}
| Enquiry | |
| Contact us | ||
|
||