+ 1
what is the regex for printing only the domain from a url?
i have to do it with the use of regex only.. if i give the input as : http://www.google.com The output should be : www.google.com
6 Respostas
+ 13
import re
pattern = 'http[s]?://((?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)'
url ='https://www.sololearn.com/Discuss/1329933/?ref=app'
print(re.findall(pattern, url))
#Pattern Source: http://www.noah.org/wiki/RegEx_Python
+ 6
Mert Yazıcı congratulations for level 16!
+ 4
You could do it with string slicing:
x = "mmmmm.aaaaa@sololearn.com"
print(x[x.index("@") + 1::])
+ 2
i have to do it with the use of regex only..
if i give the input as : http://www.google.com
The output should be :
www.google.com
+ 1
https://stackoverflow.com/questions/29061521/regular-expression-to-match-only-domain-from-url
0
(?<=:\/\/)?([\w]+(?:\.\w+)+)
First group is the url.
http:// and www. are optional, weird top level domain names like .co.uk also pass this. File path is ignored.
Also put escapes before symbols if Python needs it, I don't know Python myself.