Reputation: 35
How would I use regular expression to find only links that end with numbers
i've tried:
links = "'http://www.badlink.com' , 'http://good.link.com/W0QQAdIdZ567296978'"
re.findall(r'http://[\w\.\w\.\w\.-]+.*',links)
I don't know how to make python stop searching after it finds integers in the link. Best case scenario I would like the match to only occur if the link ends with (5) or more numbers
Upvotes: 0
Views: 75
Reputation: 97938
If a single number at the end is good enough:
good_links = filter(lambda x: x.startswith("http://") and
all(c in "0123456789" for c in x[-4:]), links.split("'"))
Upvotes: 1
Reputation: 44823
Try this:
re.findall(r'^http://.+?\d{5,}$',links)
Visual explanation:
Upvotes: 1