It might be easier (well, more readable anyway) to break it up into components:
my $alpha = 'a-zA-Z'; my $alphanum = $alpha.'\d'; my $any = $alphanum.'-'; my $label = qr/ (?:[$alpha]| # start with a letter \d[$any]*[$alpha]+) # or a number if there's a letter + elsewhere (?: [$any]* # followed by more stuff maybe [$alphanum] # as long as it doesn't end with +a - )? /x; $is_valid = /^(?:$label\.)*$label$/;
Note that while this matches 1912 hostnames, some newer hostnames have been belatedly declared "valid" though they do not adhere to this RFC (specifically, domains like 411.com or 800.com, which violate the "labels must not be all numbers" rule). Perhaps there is a newer RFC that supercedes 1912?

Perhaps somebody has a better solution...


In reply to Re: Re: Matching RFC1912 compliant hostnames by Fastolfe
in thread Matching RFC1912 compliant hostnames by BlueLines

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.