正则过滤IP地址和端口

IP地址

匹配0~255的表达式:

(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)

匹配0.0.0.0~255.255.255.255的表达式:

((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d))

端口

匹配0~65535的表达式:

(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{4}|[1-5]\d{4}|[1-9]\d{1,3}|[0-9])
posted @ 2020-12-01 20:55  Macrored  阅读(1168)  评论(0编辑  收藏  举报