- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Validate IP port number (1-65535)
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.
:1 | :65535 | :2546
:99999 | :0684 | :2ab23
Author Rating: The rating for this expression. Matthew Harris
Your Rating
Bad Good

Enter New Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: thanks
Name: MC
Date: 3/29/2020 5:04:06 PM
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
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
Expression mistyped: second part requests an IP with 6 digits, e.g. 655000 would do. Remove the unnecessary [0-9].

Copyright © 2001-2023, | ASP.NET Tutorials