title: Regex to Extract First Part of URL
body: <p>I need a java regex to extract parts of a URL.</p>
  
  <p>For example, take the following URLs:</p>
  
  <pre><code>http://localhost:81/example
  https://test.com/test
  http://test.com/
  </code></pre>
  
  <p>I would want my regex expression to return:</p>
  
  <pre><code>http://localhost:81
  https://test.com
  http://test.com
  </code></pre>
  
  <p>I will be using this in a Java patcher.</p>
  
  <p>This is what I have so far, problem is it takes the whole URLs:</p>
  
  <pre><code>^https?:\/\/(?!.*:\/\/)\S+
  </code></pre>