1. Expression writing: [2]
Regex_ip = "(2 [0-4] [0-9] | 25 [0-5] | 1 [0-9] [0-9] | [1-9]? [0-9]) (\. (2 [0-4] [0-9] | 25 [0-5] | 1 [0-9] [0-9] | [1-9]? [0-9]) {3 }"
It means (0-255) (point 0-255) 3 times
Echo "123.1.1.1" | grep-e "$ regex_ip"
Method 2:
Read IP
Echo $ IP | awk-F '. ''{If ($1> 256 | $1 <0) | ($2> 256 | $2 <0) | ($3> 256 | $3 <0) | ($4> 256 | $4 <0) Print $0, "is incorrect "}'
2. Notes
Because the extended regular | and? So grep must add-e
Reference
[1] Regular Expression
Http://www.cnblogs.com/mydomain/archive/2011/08/27/2155340.html
Http://www.cnblogs.com/mydomain/archive/2010/10/17/1853661.html
[2] explains the reason for this regular expression step by step
Http://blog.chinaunix.net/space.php? Uid = 20231929 & Do = Blog & id = 2747894
[3] common Regular Expressions
Http://hi.baidu.com/puma525/blog/item/8251fbd39ba76dcba8ec9a4d.html
[4] differences between bre and ere
Http://www.4ucode.com/Study/Topic/127403
Http://blog.csdn.net/cheungjustin/article/details/5897982
Ere modified some of Bre syntax and added the following syntax symbols:
? -Match at most once (zero or one match)
+-Match at least once (one or more times ).
|-Or operation. both the left and right operands can be considered as a subexpression.
At the same time, ere cancels the escape character reference syntax for the subexpression "()" and number of times matching "{m, n}" syntax symbols. When these two syntax symbols are used,You do not need to add escape characters..
At the same time, ere also removes the ability of subexpressions with non-regular semantics to forward references.