Regular Expressions 101

Community Patterns

Port & Port rage regex

1

Regular Expression
ECMAScript (JavaScript)

/
^(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4})$|^(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4})-(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[0-9]{1,4})$
/

Description

Matches port and port range max to 2^16. Match: 1 2 3 99 1001 65535 1-100 80-90 1-65535

Not match: 65536-75535 1-65536

Submitted by Dan - 8 years ago