How to use regular expressions in javascript to detect IP address _ javascript

Source: Internet
Author: User
This article describes how to use a regular expression to detect IP addresses in javascript. For more information, see the regular expression below:

(2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?)

(2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?)

The red block indicates that the first character is 2, the second character is 0 to 4, and the third character is any digit. Indicates 200 ~ 249.

Green block: the first character is 2, the second character is 5, and the third character is 0 to 5. Indicates 250 ~ 255.

The blue block indicates that the first character is 0, or 1, or does not exist. The second character is a number and the third character is a number, this character does not exist. 1 ~ 199, with a leading zero.

"|" Indicates "or", as long as the meaning of any one of the three blocks is satisfied.

"(" And ")" indicates that this is a group.

(2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?)

{3} indicates repeated three times. For example, "255.255.255 .".

(2 [0-4] \ d | 25 [0-5] | [01]? \ D ?) \.) {3} (2 [0-4] \ d | 25 [0-5] | [01]? \ D ?)

The last group means the same detection after.

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.