使用正则表达式验证 IP [英] Validating an IP with regex

查看:58
本文介绍了使用正则表达式验证 IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证格式为 000000000 到 255255255 的 IP 范围,在 3 组数字之间没有任何分隔符.最终 IP 所包含的三个组中的每一个都应该是 000(是的,0 填充)到 255.

I need to validate an IP range that is in format 000000000 to 255255255 without any delimiters between the 3 groups of numbers. Each of the three groups that the final IP consists of should be 000 (yes, 0 padded) to 255.

由于这是我的第一个 stackoverflow 条目,如果我没有正确遵守礼仪,请宽容.

As this is my 1st stackoverflow entry, please be lenient if I did not follow etiquette correctly.

推荐答案

^([01]\d{2}|2[0-4]\d|25[0-5]){3}$

分为以下几个部分:

  1. 000-199
  2. 200-249
  3. 250-255

如果您决定需要 4 个八位字节而不是 3 个,只需将最后一个 {3} 更改为 {4}.此外,您也应该了解 IPv6.

If you decide you want 4 octets instead of 3, just change the last {3} to {4}. Also, you should be aware of IPv6 too.

这篇关于使用正则表达式验证 IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆