title: Get url from a string groovy
body: <p>I am working with a grails app. I need to extract only part of the url up to .com (or gov, edu, mil, org, net, etc.) from a string. </p>
  
  <p>For example:</p>
  
  <p>Input: <a href="https://stackoverflow.com/questions?=34354#es4">https://stackoverflow.com/questions?=34354#es4</a> Output:  <a href="https://stackoverflow.com/">https://stackoverflow.com/</a> </p>
  
  <p>Input: <a href="https://code.google.com/p/crawler4j/issues/detail?id=174" rel="nofollow noreferrer">https://code.google.com/p/crawler4j/issues/detail?id=174</a> Output: <a href="https://code.google.com/" rel="nofollow noreferrer">https://code.google.com/</a></p>
  
  <p>Can anyone suggest how it can be done? Also, if it can be done, I need to change https to http in the resulting string. Please help. Thanks. </p>
  
  <p>Edit: I apologize to all the downvoters that I did not include the thing that I tried. This is what i tried:</p>
  
  <pre><code>URL url = new URL(website);
  String webUrl = url.getprotocol()+"://"+url.getAuthority()
  </code></pre>
  
  <p>But I got the following error: <code>MissingPropertyException occurred when processing request: [POST] /mypackage/resource/crawl</code></p>