[EMAIL PROTECTED] wrote:
> 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. 

It doesn't match the regex.  Here is a breakdown:

^               Anchor at beginning of string
[^\.]+?         Any number of characters that are not a period
\.              A period
\w{2,4}         2-4 "word" characters
$               End of string

"www.xx.yy" doesn't match because it has two periods and you are only
allowing for one.

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

Reply via email to