> example below, it fails to match "host-no.top-level" as a valid host > name. I modify the regex several times - but still don't get the right > outlook. > > my @hosts = qw(192.168.22.1 192.168.22.18 localhost another.host.domain > host-no.top-level my.host.domain.com); > foreach (@hosts){ > # Works ok > push (@ips, $_ ) if $_ =~ /^\d{1,3}\.\d{1,3}\.\d{1|3}/; > > # Can't match "host-no.top-level". > push (@dns, $_) if $_ =~ /^\w+-?[\w+]?\.?[\w+.{1}]*\w+$/; > }
/^\w+-?[\w+]?\.?[\w+.{1}]*\w+$/------>Here you look for only one "-" and also not allowing any other non-word charaters(like hyphen). The "." can match any character even other than "-" . You can think like this:(For IP's) search for a number with maximum 3 digits and then followed by the same kind of 3 numbers but prefixed with a dot. Try this ---> $_ =~ /^\d{1,3}[\.\d{1,3}]{3}/ You can think like this:(For DNS's) search for a WORD which may(-?) contain hyphen within it and then followed by the same kind of zero-or-more-WORDs but prefixed with a dot which is a normal dns name pattern. Try this ----> $_ =~ /^\w\w*-?\w+?[\.\w\w*-?\w+?]*$/ But this will allow IP's also in your "@dns" because \w can match digits also. -- Regards, K.Prabakar -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>