Javascript USES regular expressions to detect IP addresses
- 2020-03-30 04:26:31
- OfStack
Regular expressions:
((2 [0-4] \ d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;) \.) {3} (2 \ [0-4] d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;)
((2 [0-4] \ d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;) \.) {3} (2 \ [0-4] d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;)
The red block represents: the first character is 2, the second character is 0 to 4, and the third character is any digit. Said the 200 ~ 249.
The green blocks represent: the first character is 2, the second character is 5, and the third character is 0 to 5. Said the 250 ~ 255.
The blue block represents: the first character is 0, or 1, or may not have this character, the second character is any digit, the third character is any digit, may not have this character. Represents 1~199, which can have leading zeros.
"|" means "or," as long as it satisfies any one of the three.
The "(" and") "before and after represent a group
((2 [0-4] \ d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;) \.) {3} (2 \ [0-4] d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;)
{3} represents three repetitions. Such as "255.255.255.".
((2 [0-4] \ d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;) \.) {3} (2 \ [0-4] d 25 [0 to 5) | | [01] & # 63; \ d \ d & # 63;)
The last group means the same as above, adding the same test after "."