# sub-domain = Let-dig [Ldh-str] # Let-dig = ALPHA / DIGIT # Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
you can see that it matches the BNF notation exactly:
my $subdomain = '(?:[a-zA-Z0-9](?:[-a-zA-Z0-9]*[a-zA-Z0-9])?)'; <-----------><---------> *(A/D/"-") Let-dig <---------><---------------------------> Let-dig [Ldh-str]
Yeah, after sleeping on this, I see that you (Peter) are correct that the original regex (with the missing ? added) is the best/only way to go.
No special reason, I think. When I wrote the regexps, I just literally translated the BNF to regexps. I was sorely tempted to "optimize" the regexps, but resisted (mostly) because I wanted to make it easy to verify that the regexps do indeed implement the BNF.
And you were right here too; I was overthinking the problem (and misreading the BNF to boot ;). What I committed was just the addition of the question mark, so we are all set.
John