In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the regular expression that matches the IP address and domain name". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the regular expression that matches the IP address and domain name".
A complete domain name, from the root domain, top-level domain, second-level, third-level. Domain names are composed of letters, numbers and minus signs (the first letter cannot be a minus sign), case-insensitive, and no more than 63 in length.
Individual names can be matched by the regular expression [a-zA-Z0-9] [- a-zA-Z0-9] {0google 62}, while a complete domain name includes at least two names (such as google.com, consisting of google and com), and finally a dot that represents the root domain (in the specification, the last dot is the full domain name, but it is generally believed that a domain name that includes more than two names is also a full domain name. Even if there is no point behind it).
A regular expression that matches the full domain name:
The copy code is as follows:
[a-zA-Z0-9] [- a-zA-Z0-9] {0a-zA-Z0 62} (\. [a-zA-Z0-9] [- a-zA-Z0-9] {0girls 62}) +\?
An IP string consists of four segments, each of which is a number of 0255. the segments are separated by a decimal point. For example, 61.139.2.69 is a legal IP string.
It is certainly irresponsible if the regular expression is written as\ d {1Magne3} (\.\ d {1Magne3}) {3}, because it can match illegal IP strings such as 300.400.555.666.
There are several ways to match a number between 0,255, here is one of them:
Match regular expression description
0# 9\ d single number
1099 [1-9]\ d double digits
100,199 1\ d\ d three digits with a hundred digits of 1
2000249 2 [0-4]\ d three digits, 100 digits are 2, ten digits are 09
250 '255 25 [0-5] three digits, 100 digits are 2, 10 digits are 5, and individual digits are 0-5.
Write a regular expression, that is, (\ d | ([1-9]\ d) | (1\ d\ d) | (2 [0-4]\ d) | (25 [0-5])), but when such a regular expression matches a string like 254, it will match 2, 5, 4 respectively, and get 3 matches, which can not achieve the desired effect. The right thing to do is to reverse the order to ((25 [0-5]) | (2 [0-4]\ d) | (1\ d\ d) | ([1-9]\ d) |\ d), because in the matching behavior of (xxx | yyy), the search is from left to right.
The complete regular expression is:
The copy code is as follows:
((25 [0-5]) | (2 [0-4]\ d) | (1\ d) | ([1-9]\ d) |\ d) (\. (25 [0-5]) | (2 [0-4]\ d) | (1\ d) | (1-9]\ d) |\ d) {3}
Press:
A number with a high order of 0 like 061 cannot be matched.
Therefore, the top (1. Part) is the correct and complete version, (2. Part) is written in an one-sided way.
Thank you for reading, the above is the content of "what is the regular expression matching IP address and domain name". After the study of this article, I believe you have a deeper understanding of what the regular expression matching IP address and domain name is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.