Regex - extract only domain name from url ?

  • Автор темы Автор темы aleksa77
  • Дата начала Дата начала
(?<!www\.)(?<=\.)[^\/\.]{5,}(\.\w{2,4}){1,2}\/
 
  • Спасибо
Реакции: aleksa77
Projectmaker doesnt support php.

Maybe something like this

(?<=\.).*[a-z0-9\\-\\.].(com|org|net|mil|edu)
 
There is a function in C# for this. It gets the root of a domain. For example for variable url= http://bakemehappy.org/bread-recipe/ you get bakemehappy.org.

Код:
Развернуть Свернуть Копировать
var root = "";
string url = Convert.ToString(project.Variables["url"].Value); 
root = new Uri(url).Host;
root= Convert.ToString(root).Replace("www.",""); //if you do not need www
return root;
 
Я не знаю вашего буржуйского))) но думаю и так будет понятно

Код:
Развернуть Свернуть Копировать
            System.Uri sitename = new Uri("http://site.ru/ladskjfldsj/sdfsdf/2.html");
            string n = sitename.Host.ToString();

P.S n = site.ru
 
Try this method.. you will get exact domain name

Код:
Развернуть Свернуть Копировать
Uri myUri = new Uri("http://forums.asp.net/t/1110512.aspx?");
string host = myUri.Host;

and more method you can try..... http://net-informations.com/faq/asp/domain.htm

Steve





I try with this code:

^(http://|https://)[A-Za-z0-9.-]+(?!.*\|\w*$)

and from url

http://img251.imagevenue.com/loc48/th_720079906_DitaVonTeese_122_48lo.jpg

I get

http://img251.imagevenue.com

But i need only

imagevenue.com ?

Thanks
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)