in reply to Re: Exact Regex for port Number
in thread Exact Regex for port Number

Hi,Thank you ALL for your replies. in this case, I am a BIT lucky since I only have higher POTRS from 1024 to 65535 . So I can go with {4,5}

So, I go with below code. Thanks once again. Hv a wonderful day.

:[0-9]{4,5}

Replies are listed 'Best First'.
Re^3: Exact Regex for port Number
by AnomalousMonk (Archbishop) on Jun 19, 2018 at 10:12 UTC

    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:  <%-{-{-{-<