Hi Rob!

Your example using split is a bit too long. The regex worked fine. 
Can you help me understand what you did here?

Say we have www.domain4you.co.uk or https://rrp.domain-house.com
 So we substitute any character from start to the one before the first
dot with nothing, right?
 In the case of "www.domain4you.com", "www" will be truncated isn't it?

 $name =~ s/^[^\.]+//;

I hope I got the logic right.

Thanks

Babs



-----Ursprüngliche Nachricht-----
Von: Hanson, Rob [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 16. April 2004 01:36
An: 'B. Fongo'; [EMAIL PROTECTED]
Betreff: RE: Regex to match domain for cookie


It might be easier to do it with a split.

# untested
foreach (@domains) {
  my @parts = split(/\./, $_);
  my $name;
  
  if (@parts > 1) {
    shift @parts;
    $name = '.' . join('.', @parts);
  }

  print $name;
}

As a regex, this I think will work...

foreach (@domains) {
  my $name = $_;
  $name =~ s/^[^\.]+//;
  print $name;
}


-----Original Message-----
From: B. Fongo [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 15, 2004 7:29 PM
To: [EMAIL PROTECTED]
Subject: Regex to match domain for cookie


How do I match a domain name starting from the dot? 
 
# Match something like these
".domain4you.co.uk"
".domain-house.de"
 
 
This is what I have:
 
 
@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";
 
 
}
 
 
 
Babs
 
 
 



--
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