import re
x = 'my website name is www.algoexpert.com and i have other website too'
for line in x:
y = line.rstrip()
z = re.findall('.*\S+/.[a-z]{0-9}/.\S+', y)
print(z)
I just want to print the website name (www.algoexpert.com)
Issues to fix:
x is a string itself, why are you looping over it with for line in x?
[a-z]{0-9} - tries to cover only alphabetical chars, though in wrong way (could be {0,9}). The range of chars should be [a-z0-9]+ or at least - [a-z]+ (depending on the initial intention)
. should be escaped with backslash \.Fixed version (simplified):
import re
x = 'my website name is www.algoexpert.com and i have other website too'
z = re.findall('\S+\.[a-z0-9]+\.\S+', x.strip())
print(z) # ['www.algoexpert.com']
www.something.comor do you need to support stuff likefoo.something.tk? What constitutes a "website name"? Thanks for clarifying.