Title |
Test
Find
Validate IP port number (1-65535)
|
Expression |
:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3}) |
Description |
This was based on the regex in the source but it was buggy so I fixed it and then optimized it.
It matches port numbers in the form of :1 to :65535
This is designed to be plugged onto the end of your favourite url regex because when I was looking for a IPv4 regex I noticed that a lot of them either didn't match the port or matched it badly (allowing the port number to start with a 0 or be higher than 65535)
This regex solves those two problems. |
Matches |
:1 | :65535 | :2546 |
Non-Matches |
:99999 | :0684 | :2ab23 |
Author |
Rating:
Not yet rated.
Matthew Harris
|
Source |
http://social.msdn.microsoft.com/Forums/en-US/regexp/thread/bc7f5bc2-ac30-434b-9ae9-908d602ee6ea |
Your Rating |
|
Title: thanks
Name: MC
Date: 3/29/2020 5:04:06 PM
Comment:
Just wondering if this counts as further optimisation or not?
:(6553[0-5]|655[0-2][0-9]\d|65[0-4](\d){2}|[1-5](\d){4}|[1-9](\d){0,3})
Title: Thx
Name: pach
Date: 10/30/2012 9:11:59 AM
Comment:
thank you Matthew for this expression ! thanks to Szaky too. you're perfectly right
Title: mistyped
Name: Szaky
Date: 1/20/2010 2:22:48 AM
Comment:
Expression mistyped: second part requests an IP with 6 digits, e.g. 655000 would do. Remove the unnecessary [0-9].