KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I made a regex for port numbers (before you say this is a bad idea, its going into a bigger regex for URL's which is much harder than it sounds). My coworker said this is really bad and isn't going to catch everything. I disagree. I believe this thing catches everything from 0 to 65535 and nothing else, and I'm looking for confirmation of this. Single-line version (for computers): /(^[0-9]$)|(^[0-9][0-9]$)|(^[0-9][0-9][0-9]$)|(^[0-9][0-9][0-9][0-9]$)|((^[0-5][0-9][0-9][0-9][0-9]$)|(^6[0-4][0-9][0-9][0-9]$)|(^65[0-4][0-9][0-9]$)|(^655[0-2][0-9]$)|(^6553[0-5]$))/ Human readable version: /(^[0-9]$)| # single digit (^[0-9][0-9]$)| # two digit (^[0-9][0-9][0-9]$)| # three digit (^[0-9][0-9][0-9][0-9]$)| # four digit ((^[0-5][0-9][0-9][0-9][0-9]$)| # five digit (up to 59999) (^6[0-4][0-9][0-9][0-9]$)| # (up to 64999) (^65[0-4][0-9][0-9]$)| # (up to 65499) (^655[0-2][0-9]$)| # (up to 65529) (^6553[0-5]$))/ # (up to 65535) Can someone confirm that my understanding is correct (or otherwise)?
Tags (comma-separated)
Save Edits
Cancel