What are the Java regular expressions for matching IPv4 and IPv6 strings?

前端 未结 6 1827
抹茶落季
抹茶落季 2020-12-03 18:57

Looking for a string to pass to String#matches(String) that will match IPv4, and another to match IPv6.

6条回答
  •  [愿得一人]
    2020-12-03 19:24

    The regex allows the use of leading zeros in the IPv4 parts.

    Some Unix and Mac distros convert those segments into octals.

    I suggest using 25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d as an IPv4 segment.

提交回复
热议问题