First, learn the syntax rules for regular expressions, as follows:
The IP address is usually similar: 10.221.105.225 format, cannot start with 0, each field maximum not more than 255, not less than 0
IP matching rules:
String IP = "([1-9]|[ 1-9][0-9]|1\\D\\D|2[0-4]\\D|25[0-5]) \ \. "+ " ([1-9]|[ 1-9][0-9]|1\\D\\D|2[0-4]\\D|25[0-5]) \ \. "+ " ([1-9]|[ 1-9][0-9]|1\\D\\D|2[0-4]\\D|25[0-5]) \ \. "+ " ([1-9]|[ 1-9][0-9]|1\\D\\D|2[0-4]\\D|25[0-5]) ";
Explain: If the current field is only 1 bits, then only a number in 1-9, if it is two bits, because the beginning can not be 0, so the first digit is 1-9 and the single digit can be 0-9, similarly, if it is 3 digits, percentile is 1, the case, very bit and single-digit is not required, percentile is 2, So very bit can only be 0-4, single-digit no requirements, percentile and very bit is 255, then the only digit is 0-5, the first three to remember the back plus one.
Regular expressions verify IP address legitimacy