Regular expressions verify IP address legitimacy

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.