When I am reading the book called
<the way="" ruby="">,I find there is a very clever regular expression which determines a string whether a string is a valid IPv4 address.The following is the expression:
num = "(\\d|[01]?\ \ d\ \ d|2[0-4]\\d|25[0-5])"
pat = "^#{ num} \.#{ num} \.#{ num} \.#{ num} $"
And the following is for the </the> IPv6 addresses:
num = "[0-9A-Fa-f]{ 0,4} "
pat = "^" + "#{ num} :"*7 + "#{ num} $"
num = "(\\d|[01]?\ \ d\ \ d|2[0-4]\\d|25[0-5])"
pat = "^#{ num} \.#{ num} \.#{ num} \.#{ num} $"
And the following is for the </the> IPv6 addresses:
num = "[0-9A-Fa-f]{ 0,4} "
pat = "^" + "#{ num} :"*7 + "#{ num} $"