<p>To get only the second to last chunks of the domain, you could modify your regex to have:</p>
<pre><code>[re.search('https?://(?:[^/]+\.)?([A-Za-z_0-9-]+)\.[^/.]+(?:/.*)?', url).group(1)
 for url in urls]
</code></pre>
<p>Output:</p>
<pre><code>['arxiv', 'doi', 'scopus']
</code></pre>
<h5>urllib</h5>
<p>@AbdulNiyasPM had a nice answer, too bad it was deleted, you can modify it to get what you want:</p>
<pre><code>from urllib.parse import urlparse
[urlparse(url).hostname.split('.')[-2]
 for url in urls]
</code></pre>
How to extract just domain names from urls?
<p>I have a following list of URLs:</p>
<pre><code>urls = [&quot;http://arxiv.org/pdf/1611.08097&quot;, &quot;https://doi.org/10.1109/tkde.2016.2598561&quot;, &quot;https://www.scopus.com/inward/record.uri?partnerID=HzOxMe3b&amp;scp=85116544648&amp;origin=inward&quot;]
</code></pre>
<p>from each element of the list, I am trying to extract just the domain names like: <code>arxiv</code>, <code>doi</code>, <code>scopus</code>.</p>
<p>For that I have a code:</p>
<pre><code>import re

for url in urls:
    print(re.search('https?://([A-Za-z_0-9.-]+).*', url).group(1))
</code></pre>
<p>The output of print:</p>
<pre><code>arxiv.org
doi.org
www.scopus.com
</code></pre>
<p>How can I modify the above regex to extract just the domain and no other stuff like <code>www.</code>, <code>.com</code>, <code>.org</code> etc?</p>
<p>Thanks in advance.</p>