I'm trying to get a working regex syntax to match the following values. The field is able to contain either
- Comma-separated values or a single value. Such as "22" or "22,456"
- A range of ports with a dash. Such as "22-600"
With values possible from 1 to 65535
Attempts
Matches a single port correctly, however doesn't support a "," or "-"
^(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}|[1-9][0-9]{1,3}|[0-9])(?:,(?1))*$
Doesn't match a single port but does match multiple comma seperated ports
^(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}|[1-9][0-9]{1,3}|[0-9])(?:,(?1))(?:,(?1))*$
Doesn't match a single port but does match a port range
^(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}|[1-9][0-9]{1,3}|[0-9])(?:-(?1))(?:(?1))*$