Here you can find the source of isIpV6RegexValid(String strIp)
Parameter | Description |
---|---|
strIp | IP string. |
public static boolean isIpV6RegexValid(String strIp)
//package com.java2s; import java.util.regex.Pattern; public class Main { /**/* w ww . j ava 2s. c o m*/ * check if IP v6 string is valid by regex. * * @param strIp * IP string. * @return true if valid, false if not. */ public static boolean isIpV6RegexValid(String strIp) { final String regexV6 = "^([\\da-fA-F]{1,4}:){6}" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^::([\\da-fA-F]{1,4}:){0,5}" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^([\\da-fA-F]{1,4}:):([\\da-fA-F]{1,4}:){0,4}" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^([\\da-fA-F]{1,4}:){2}:([\\da-fA-F]{1,4}:){0,3}" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^([\\da-fA-F]{1,4}:){3}:([\\da-fA-F]{1,4}:){0,2}" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^([\\da-fA-F]{1,4}:){4}:([\\da-fA-F]{1,4}:){0,1}" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^([\\da-fA-F]{1,4}:){5}:" + "((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|" + "^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$|" + "^:((:[\\da-fA-F]{1,4}){1,7}|:)$|" + "^[\\da-fA-F]{1,4}:((:[\\da-fA-F]{1,4}){1,6}|:)$|" + "^([\\da-fA-F]{1,4}:){2}((:[\\da-fA-F]{1,4}){1,5}|:)$|" + "^([\\da-fA-F]{1,4}:){3}((:[\\da-fA-F]{1,4}){1,4}|:)$|" + "^([\\da-fA-F]{1,4}:){4}((:[\\da-fA-F]{1,4}){1,3}|:)$|" + "^([\\da-fA-F]{1,4}:){5}((:[\\da-fA-F]{1,4}){1,2}|:)$|" + "^([\\da-fA-F]{1,4}:){6}:([\\da-fA-F]{1,4})?$|" + "^([\\da-fA-F]{1,4}:){7}:$"; Pattern pattern = Pattern.compile(regexV6); boolean isRegular = pattern.matcher(strIp).matches(); return isRegular; } }