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

2
  • Does this answer your question? Regular expression to find URLs within a string Commented Apr 12, 2020 at 18:38
  • Can you give some samples of your URLs? Commented Apr 12, 2020 at 18:51

1 Answer 1

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@:%_\+.~#()?&//=]*)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.