title: What's the best way to parse URLs to extract the domain?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/278622/ruby-code-to-extract-host-from-url-string">Ruby code to extract host from URL string</a>  </p>
  </blockquote>
  
  
  
  <p>I found this module called <a href="http://www.ruby-doc.org/stdlib/libdoc/uri/rdoc/classes/URI.html" rel="nofollow noreferrer">URI</a> which can parse the url. (I'm pretty new to ruby. Is 'module' synonymous with 'library' in this case?) You can then extract the host name.</p>
  
  <pre><code>uri = URI.parse("http://www.ruby-lang.org/")
  ...
  p uri.host
  # =&gt; "www.ruby-lang.org"
  </code></pre>
  
  <p>From this, I suppose you could remove 'www.' and keep other subdomains using regular expressions.</p>
  
  <p>Does anyone have a more straight-forward alternative or does this approach seem right?</p>