But  :[0-9]{4,5} allows port numbers like 1000 and 99999; more range checking is in order. Maybe something like:

c:\@Work\Perl\monks>perl -wMstrict -le "for my $pn (qw( :1 :23 :456 :999 :1000 :1023 :1024 :9999 :10000 :65535 :1024x :9999x :10000x :65535x :65536 :99999 :123456 :x :foo : ), '', ' ', @ARGV) { my $pn_ok = $pn =~ m{ : (\d{4,5}) (?! \d) }xms && $1 >= 1024 && $1 <= 65535; print qq{'$pn' }, $pn_ok ? 'in range' : 'BAD'; } " ':1' BAD ':23' BAD ':456' BAD ':999' BAD ':1000' BAD ':1023' BAD ':1024' in range ':9999' in range ':10000' in range ':65535' in range ':1024x' in range ':9999x' in range ':10000x' in range ':65535x' in range ':65536' BAD ':99999' BAD ':123456' BAD ':x' BAD ':foo' BAD ':' BAD '' BAD ' ' BAD


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: Exact Regex for port Number by AnomalousMonk
in thread Exact Regex for port Number by theravadamonk

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.