title: IP address format check
body: <p>I am developing a <strong>Ruby on Rails</strong> application by using <strong>Ruby v1.8.7</strong> . My question is more about <strong>Ruby</strong> language.</p>
  
  <p>I know there is a build-in Ruby library named <a href="http://www.ruby-doc.org/stdlib-1.8.7/libdoc/ipaddr/rdoc/IPAddr.html" rel="nofollow">IPAddr</a> in <strong>Ruby v1.8.7</strong> . It handles IP address related issues well. But, seems it does not provide any method to check IP address format.</p>
  
  <p>Could someone provide me <strong>a good way to check IP address format</strong>(IPv4 and IPv6 addresses) in Ruby? Thank you.</p>
  
  <p><strong>P.S.</strong> </p>
  
  <p>I tried a regular expression way:</p>
  
  <pre><code>ip_regex = ^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.
  ([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$
  
  ip_addr='127.0.0.3'
  ip_addr =~ ip_regex
  </code></pre>
  
  <p>But it does not work...</p>