Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to verify the correctness of IP and port format through regular expressions

Shulou Source: shulou.com Published: 2022-06-02 04:58:19 10月03日 Update

This article will explain in detail how to verify the correctness of IP and port format through regular expressions. Xiaobian thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Regular expression for 1:ip:

The format is made up of "." Four segmented parts, each with a range of 0-255

The regularity of each paragraph can be divided into several parts: 200-255, 100-1999, 10-99, 0-9.

Regular expression for each part: 2 [0-4]\ d | 25 [0-5]; 1\ d {2}; [1-9]\ d;\ d

So it is connected to\ d | [1-9]\ d | 1\ d {2} | 2 [0-4]\ d | 25 [0-5]

Then the rule of IP is (\ d | [1-9]\ d | 1\ d {2} | 2 [0-4]\ d | 25 [0-5]). (\ d | [1-9]\ d | 1\ d {2} | 2 [0-4]\ d | 25 [0-5])\. (\ d | [1-9]\ d | 1 [0-4] 2} | 25 [0-5])\. (\ d | [1-9]\ d | 1\ d {2} | 2 [0-4]\ d | 25 [0-5])

Expressed in JS as / ^ (\ d | [1-9]\ d | 1\ d {2} | 2 [0-4]\ d | 25 [0-5])\. (\ d | [1-9]\ d | 1\ d {2} | 2 [0-4])\ d | 25 [0-5])\. (\ d | [1-9]\ d | 1\ d {2} | 25 [0-5])\. (\ d | [1-9]\ d | 1\ d {2} | 2 [0-5]). -4]\ d | 25 [0-5]) $/

2: regular expression of the port:

The format is 0-65535.

The same principle can be divided into several parts: 60000-65535 10 000-59999 10-9999 10-99 10-99 10-9

The regularity of each part is: 6 [0-4]\ d {4} | 65 [0-4]\ d {2} | 655 [0-2]\ d | 6553 [0-5]; [1-5]\ d {4}; [1-9]\ d {3}; [1-9]\ d {2}; [1-9]\ d; [0-9]

The results are as follows: ([0-9] | [1-9]\ d {1Magne3} | [1-5]\ d {4} | 6 [0-4]\ d {4} | 65 [0-4]\ d {2} | 6553 [0-5])

Expressed in JS as: / ^ ([0-9] | [1-9]\ d {1pr 3} | [1-5]\ d {4} | 6 [0-4]\ d {4} | 65 [0-4]\ d {2} | 6553 [0-5]) $/

On "how to verify the correctness of IP and port format through regular expressions" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Regular expression part format port that is article correctness verification middle table more good practical content article is composed of knowledge scope reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Linux Shulou Information Docker