正则表达式对IP地址的限制

正则表达式 ^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$
匹配 127.0.0.1 | 255.255.255.0 | 192.168.0.1
不匹配 1200.5.4.3 | abc.def.ghi.jkl | 255.foo.bar.1

 

正则表达式 ^((0|1[0-9]{0,2}|2[0-9]{0,1}|2[0-4][0-9]|25[0-5]|[3-9][0-9]{0,1})\.){3}(0|1[0-9]{0,2}|2[0-9]{0,1}|2[0-4][0-9]|25[0-5]|[3-9][0-9]{0,1})(?(\/)\/([0-9]|[1-2][0-9]|3[0-2])|)$
匹配 192.168.0.1 | 192.168.0.1/32 | 255.255.0.0/1
不匹配 010.0.0.0 | 192.168.0.1/33 | 256.0.1.55

 

正则表达式 ^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$
匹配 97.67.44.20 | 199.154.37.214 | 127.0.0.1
不匹配 63.125.94.287 | 140.370.a.187 | 94.923.1

 

正则表达式 /^(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\/(\d{1}|[0-2]{1}\d{1}|3[0-2])$/
匹配 192.168.100.1/24 | 0.0.0.0/0
不匹配 192.168.100.1/33 | 0.0.0.0/90



正则表达式 \d+\.\d+\.\d+\.\d+
匹配 127.0.0.1 | 255.255.255.0 | 192.168.0.1
不匹配 @#.5.4.3 | abc.def.ghi.jkl | 255.foo.bar.1

 

正则表达式 ^((\d|\d\d|[0-1]\d\d|2[0-4]\d|25[0-5])\.(\d|\d\d|[0-1]\d\d|2[0-4]\d|25[0-5])\.(\d|\d\d|[0-1]\d\d|2[0-4]\d|25[0-5])\.(\d|\d\d|[0-1]\d\d|2[0-4]\d|25[0-5]))$
匹配 1.198.0.1 | 100.10.0.1 | 200.200.123.123
不匹配 ..12.23 | a.23.345 | 400.500.300.300

 

正则表达式 ^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$
匹配 0.0.0.0 | 255.255.255.02 | 192.168.0.136
不匹配 256.1.3.4 | 023.44.33.22 | 10.57.98.23.

 

正则表达式 ^(http|https|ftp)\://(((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])|([a-zA-Z0-9_\-\.])+\.(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|uk|me))((:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*)$
匹配 http://www.allkins.com | http://255.255.255.255 | http://allkins.com/page.asp?action=1
不匹配 http://test.testing

 

正则表达式 ^(([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+)\.([0-2]*[0-9]+[0-9]+))$
匹配 113.173.40.255 | 171.132.248.57 | 79.93.28.178
不匹配 189.57.135 | 14.190.193999 | A.N.D.233



正则表达式 \b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b
匹配 217.6.9.89 | 0.0.0.0 | 255.255.255.255
不匹配 256.0.0.0 | 0978.3.3.3 | 65.4t.54.3

posted @ 2015-01-24 15:56  周人假的  阅读(1986)  评论(0编辑  收藏  举报