A complete domain name, by the root domain, top-level domain, level two, three ... Domain name composition, each level of domain name separated by point, each domain name by letter, number and minus sign (the first letter can not be a minus), case-insensitive, not more than 63.
A single name can be matched by a regular expression [a-za-z0-9][-a-za-z0-9]{0,62}. And the complete domain name includes at least two names (such as Google.com, made up of Google and COM, you can finally have a point that represents the root domain (in the specification, the last point is the full domain name, but generally think that include more than two names of the domain name is also a complete domain name, even if there is no point behind it).
Regular expression that matches the full domain name:
Copy Code code as follows:
[A-za-z0-9] [-a-za-z0-9] {0,62} (\. [A-za-z0-9] [-a-za-z0-9] {0,62}) +\.?
An IP string, composed of four paragraphs, each segment is a 0~255 number, segments and segments separated by a decimal point, such as 61.139.2.69 is a legitimate IP string.
If the regular expression is written as \d{1,3} (\.\d{1,3}) {3}, it is no doubt irresponsible because it can match an illegal IP string such as 300.400.555.666.
To match the number between a 0~255, there are several ways to match it, and here's one:
Match Regular Expression description
0~9 \d Single digit
10~99 [1-9]\d two digits
100~199 1\d\d Hundred is 1 three digits
200~249 2[0-4]\d Three digits, the Hundred is 2, 10 is 0~9
250~255 25[0-5] Three digits, the Hundred is 2, 10 is 5, the single-digit is 0~5
Written as a regular expression, that is: (\d| ( [1-9]\d) | (1\d\d) | (2[0-4]\d) | (25[0-5]), but such regular expressions match 2, 5, 4, and get 3 matches to match 254 of such strings, and the correct approach is to reverse the order ((25[0-5)) | ( 2[0-4]\D) | (1\d\d) | ([1-9]\d) |\d), because it is searched from left to right in this matching behavior (xxx|yyy).
The complete regular expression is:
Copy Code code as follows:
((25[0-5]) | (2[0-4]\d) | (1\d\d) | ([1-9]\d) |\d) (\. ( (25[0-5]) | (2[0-4]\d) | (1\d\d) | ([1-9]\d) |\d)) {3}
By:
Numbers like 061 with a high of 0 cannot be matched.
Therefore, the top (1 part) of the writing is the correct full version, (2) The writing is more one-sided