0

I'm having trouble finding a regular expression that works with my domain name. I do not know if I have a special domain name, but none of the examples I've found are working for me.

Here is my host name:

81-232197-178.cust.bluewin.ch

and here is my regex:

^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$

but it doesn't match.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
Mehdi Bugnard
  • 3,889
  • 4
  • 45
  • 86
  • Could you show us the regex you are currently using that doesn't match? – bluevector May 31 '12 at 19:17
  • Sorry ! ("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9-][a-zA-Z0-9]).)([A-Za-z]|[A-Za-z][A-Za-z0-9-]*[A-Za-z0-9])$) – Mehdi Bugnard May 31 '12 at 19:23
  • Can't you just include a literal in the expression? – evanmcdonnal May 31 '12 at 19:26
  • ^ ^ I need for my application on Windows 8! I code a application network utility to retrieve information ,the ip adress, host name etc. .. I get the source code of the site, http://mon-ip.com and I research the value with a' RegularExpression – Mehdi Bugnard May 31 '12 at 19:36
  • There are some problems with your regular expression. It does not allow the hostname to start with a digit. Also, it will only match two-segment name. The dot (.) is a special character in a regular expression. You need to put a backslash in front of it. The first segment will only match one character or three character names (after you put in the backslash). Try searching for "regular expression to match dns name". They're out there. – Carl Raymond May 31 '12 at 19:42
  • ok i search now for a dns pattern – Mehdi Bugnard May 31 '12 at 19:50
  • ^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?<!-)$ - No Work @"([a-zA-Z0-9\-\.]+):(.[^:]+)" - No Work atc.. I think creating a pattern like this is far too complex to manage in the numbers of possibilities of formats. Thank you so much time stuck with me. Finally I go look for an alternative to the regular expression ... – Mehdi Bugnard May 31 '12 at 20:18

2 Answers2

0

If the number of periods(.) is not variable you could use the pattern below:

([0-9]*-[0-9]*-[0-9]*).([0-9A-Za-z]*).([0-9A-Za-z]*).([0-9A-Za-z]*)
dharmendra
  • 33
  • 1
  • 7
  • it returns me this as result: -8859-1 "/ 31-05-2012 20 - One-click media -> – Mehdi Bugnard May 31 '12 at 20:22
  • I have found this and its WORK ! But i don't now if he work for another hostname/dns.. --->@"([0-9a-zA-Z.-_]{3,}[.]){3,6}[0-9a-zA-Z]{2,} – Mehdi Bugnard May 31 '12 at 21:01
0

If you are screen-scraping that website, you're probably better looking for the adjacent text and taking the string out of the next element in the DOM, rather than trying to find a regular expression that matches just that text in the page.

Malcolm
  • 1,239
  • 1
  • 14
  • 25