RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Validate optional 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 is the same as my regex listed in the source except that it is wrapped in (regex)? which makes it optional. The intended use for this regex is to be combined with buggy url/ip regex's to strengthen the port matching. It matches port numbers in the form of :1 to :65535 and also allows no port to be entered. I noticed that a lot of url/ip regexs 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 | no port entered
Non-Matches
:99999 | :0684 | :2ab23
Author Rating: Not yet rated. Matthew Harris
Source http://regexlib.com/REDetails.aspx?regexp_id=2814
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
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: wrong exp
Name: Pik
Date: 10/14/2013 10:24:32 AM
Comment:
i think, it is necessary to remove [0-9] the second part of expr correct expression is (:(6553[0-5]|655[0-2]\d|65[0-4](\d){2}|6[0-4](\d){3}|[1-5](\d){4}|[1-9](\d){0,3}))?


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials