Regex to get domain with different protocols
<p>I have this regex, which extracts domain name from string.</p>

<pre><code>var matches = str.match(/^https?\:\/\/([^\/:?#]+)(?:[\/:?#]|$)/i);
</code></pre>

<p>I would like the same RegEx, including other protocols like rstp. For example:</p>

<pre><code>"http://www.example.com/a/".match(/^https?\:\/\/([^\/:?#]+)(?:[\/:?#]|$)/i)
</code></pre>

<p>Result: <code>["http://www.example.com/", "www.example.com"]</code></p>

<p>I have tried this:</p>

<pre><code>"http://www.example.com/a/".match(/^(http|https|rtsp)\:\/\/([^\/:?#]+)(?:[\/:?#]|$)/i)
</code></pre>

<p>But it returns http too: <code>["http://www.example.com/", "http", "www.example.com"]</code></p>

<p>I would like the same output.</p>

<p>Thanks.</p>