Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

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

Description

Matches a TCP or UDP port. This will only match a string of digits between 0-65535.

It does not support zero-padded ports.

Submitted by anonymous - 6 years ago