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.