> -----Original Message-----
> From: Babale Fongo [mailto:[EMAIL PROTECTED]
> 
> How do I match a domain name starting from the dot? 
>  
>  
> @domains = ("http://www.domain.com ", "http://www.domain4you.co.uk  
>         "http://www.domain-house.de"; "https//rrp.cash-day.com"
>       );
>  
>  
> foreach (@domains){
>  
>             $_ =~ /^\D ([\.A-Za-z0-9]+[\.\D])$/; # What is wrong here?
> # Need ".domain.com", but I get "ww.domain.com"
>             $x = $1;
>             print "$x";
>  
>  
> }
>  

IŽd say that your regex does not match on any of the domains - you're
searching for
1) a non digit "\D"
2) followed by a space
...
If you ask me, this cannot work in domain names, but then I don't know 
why you're getting any results at all...

Personally, I'd write the regex like this:

  m!(?:.*?)://(?:www)*(.*)!;

This translates into:
- (?:.*?) any characters, but non-greedy (stop matching when you "see" the
next characters.
- the "://" sequence
- an optional "www"
- all the rest

Please note that the "?:" at the beginning of a pair of brackets means that
this bracket is not translated into one of the $1,$2,...-variables, but is
used for grouping only.

The full script then looks like this:

#!/usr/bin/perl -w

use strict;

my @domains = ("http://www.domain.com ", "http://www.domain4you.co.uk";,
                   "http://www.domain-house.de";, "https://rrp.cash-day.com";
              );
 
foreach (@domains){
                        
                m!(?:.*?)://(?:www)*(.*)!;
                print "$1\n";
}

HTH,

Philipp Traeder
ImmobilienScout24.de

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to