Apologies if this has been asked before but im wrecking my head over it and I've googled for hours on this one trying to see if there is a similar solution.
I've a list of url's in which the last 6 characters within '/' '/' are digits eg: www.test.com/nothere/432432/
I'm trying to write the code so that if there is a match to the substring in the position its in in the string it doesnt get added to the list. The url's im "looking at" are all of the same format hence the use of the regex in the example.
I've tried various if re.match if re.search etc etc and nothing i can put together seems to work.
This is my latest attempt:
list = ['www.test.com/nothere/432432/', 'www.test.com/nothere/685985/', 'www.test.com/nothere/655985/', 'www.test.com/nothere/112113/']
regex = re.compile(r'(/\d{6}/)')
filtered = [i for i in list if not regex.match(i)]
print(filtered)
My understanding for this is that if the regex.match(i) is not triggered then the item gets added. Otherwise dont. But that is clearly not the case and it adds them all irregardless :/
Any and all help is appriciated.
Thanks!
EDIT
Another version ive tried which does nothing:
regex = re.match(r'(/\d{6}/)', Adlink) in allAdLinks
if regex:
allAdLinks.remove(Adlink)
print(allAdLinks)
else:
print("try again")
continue