0

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

Virus
  • 315
  • 1
  • 5
  • 9
  • Does this answer your question? [Regular expression to find URLs within a string](https://stackoverflow.com/questions/6038061/regular-expression-to-find-urls-within-a-string) – Kent Shikama Apr 12 '20 at 18:38
  • Can you give some samples of your URLs? –  Apr 12 '20 at 18:51

1 Answers1

3

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@:%_\+.~#()?&//=]*)