D
D
Dima2019-12-13 22:09:51
Regular Expressions
Dima, 2019-12-13 22:09:51

How to cut a domain from a URL without www. using RegExp?

There are page addresses, in Sublime Text you need to quickly cut out only the domain without "www.". The regular expression itself is almost ready (found) but I can’t finish it (misunderstand)
.*://|/.*

https://domen.site.ru/podsait/03285926/#2412747495
http://www.site.ru/site/24722305
https://www.domen.site.ru/site/247493215/site
site.ru

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dodo512, 2019-12-13
@qpz

https://regex101.com/r/gFBb8y/3
Find: https?://(?:www\.|)([\w.-]+).*
Replace:$1

Y
YOin, 2021-07-29
@YOin

.*://|w\.*|/.*

A
Ankord, 2022-02-22
@Ankord

import re
def domain_name(url):
match = re.search(r'[./]?(?:www.)?\w+\-?\w+[.]', url)
s = match[0]
s = s.replace('www', '')
s = s.replace('.', '')
s = s.replace('/', '')
return s

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question