import re with open("pathurl_example.txt") as file: for line in file: urls = re.findall('https?://(?:[-w.]|(?:%[da-fA-F]{2}))+', line) print(urls)