I have string like below
string = 'https://somewebsite.com/itesr0824/products/YYA-002/fdrop-tQ?position=6'
How can I find
'https://somewebsite.com/itesr0824'
with regex?
I’ve tried
re.sub('[^https://somewebsite.com/[a-zA-Z0-9].+$','',string)
but it only finds
'https://somewebsite.com/itesr0824/products/YYA'
>Solution :
import re
string = 'https://somewebsite.com/itesr0824/products/YYA-002/fdrop-tQ?position=6'
x = re.sub('https:\/\/somewebsite\.com/[\w\d]+','',string)
# where: \w - any word character, \d - any digit, + - one or more
print(x)
Prints
/products/YYA-002/fdrop-tQ?position=6