Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?P<portRange>(?P<port>6553[0-5][0-9]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[0-9])(-(?&port))?)(,(?&portRange))*$
/
gm

Description

This regex matches the format required by NSX services. It can includes single ports, port ranges, comma-separated ports, or any mix thereof.

  • Single port: 3389
  • Port range: 49123-65535
  • Comma-separated ports: 80,443
  • Mixed: 80,443,100-200

It will not match any ports above 65535

Submitted by anonymous - 6 years ago