Hi, all.

I have a sub that uses a set of URL-parsing regexes that almost works:

if ($url =~ m{^(.*)\.([^\.]+\...\...)$}) {
   $domain = $2;
   $child = $1;
}
else {
   if ($url =~ /^[^\.]+?\.\w{2,4}$/) {
      $domain = $url;                                   # "www.xx.yy" should have ended up here. . .
   }
   else {
      $url =~ m{^(.*)\.(.+\.\w{2,4}).*$};      # . . . but it ended up here
      $domain = $2;
      $child = $1;
   }
}
     
It catches almost all the URL formats it needs to, like "www.defgh.xx.yy", but it misses one possible format, "www.xx.yy". For this URL the sub that uses the regex returns "xx.yy" as the domain and "www" as the child, which means that there's still something not quite right with the regex in the second if statement. The sub should've returned "www.xx.yy" as the domain, with no child. See the comments in the code sample for where that URL landed, vs. where it should've landed.

I've ordered "Mastering Regular Expressions" but it hasn't arrived yet, so any help would be appreciated.

Thanks,

Deane
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to