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

前端 未结 6 1866
抹茶落季
抹茶落季 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:50

    Another good option for processing IPs is to use Java's classes Inet4Address and Inet6Address, which can be useful in a number of ways, one of which is to determine the validity of the IP address.

    I know this doesn't answer the question directly, but just thought it's worth mentioning.

提交回复
热议问题