Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a C# regex to parse a domain name?

Tags:

I need to parse the domain name from a string. The string can vary and I need the exact domain.

Examples of Strings:

http://somename.de/
www.somename.de/
somename.de/
somename.de/somesubdirectory
www.somename.de/?pe=12

I need it in the following format with just the domain name, the tld, and the www, if applicable:

www.somename.de

How do I do that using C#?