Parsing a URL using a regular expression
<p>I have been trying to parse an address from a string and have had partial success for select strings....</p>

<p>Currently I have </p>

<pre><code>Pattern regex = Pattern.compile("[/].*[a-zA-Z](?=\/|:|)", Pattern.DOTALL)
</code></pre>

<p>On the input string <code>https://www.google.com/</code> the current pattern gets me <code>//www.google.com</code> (which is somewhat correct) however when I try the input string <code>https://www.google.com/search?q=Regular+Expressions&amp;num=1000</code> it gives me <code>//www.google.com/search?q=Regular+Expressions&amp;num</code></p>

<p>What I am trying to do is parse the address so that it ends before <code>:</code>, <code>/</code>, or whitespace</p>

<p>I did also come up with </p>

<pre><code>Pattern regex = Pattern.compile("[.*/][^/][a-z].*[a-zA-Z](?=\/|:|)", Pattern.DOTALL) 
</code></pre>

<p>and it works (partially) with <code>https://google.com:80</code> giving me <code>/google.com</code>.</p>

<p>What am I doing wrong?</p>