Here, use the regular expression I check if the specified string is a IP address, note that the prefix 0 is not allowed, if the prefix is allowed
The problem is simple, this achievement is less efficient.
Boolean ipvalid (string s) {string regex0 = "(2 [0-4] // d)" "| (25 [0-5])"; string regex1 = "1 // D {2}"; string Regex2 = "[1-9] // D"; string regex3 = "// D"; string regex = "(" regex0 ") | (" regex2 ") | (" Regex3 ")"; regex = "(" regex ") //. (" regex ") ///. (" regex ")"; Pattern P = Pattern.Compile Regex; matcher m = p.matcher (s); return m.matches ();