Reputation: 335
i want extract rvry links in my file text file with http or https or without
i tired many code but didn't work with me Of which
import re
with open("path\url_example.txt") as file:
for line in file:
urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', line)
print(urls)
but this for started with http:// or https:// but my link doesn't start with http://www. or https://www. and
Upvotes: 0
Views: 185
Reputation:
You can use this regex if you have different protocols:
(.*:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)
Upvotes: 3