У меня есть строка, как этотRegex, чтобы извлечь все адреса из строки
http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/
Я хотел бы, чтобы извлечь все URL/webaddress в массив. например
urls = ['http://example.com/path/topage.html','http://twitter.com/p/xyan',.....]
Вот мой подход, который не работал.
import re
strings = "http://example.com/path/topage.htmlhttp://twitter.com/p/xyanhshttp://httpget.org/get.zipwww.google.com/privacy.htmlhttps://goodurl.net/"
links = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', strings)
print links
// result always same as strings
Это должно полезно вам: http://regex101.com. Вы можете поиграть с вашим регулярным выражением, чтобы посмотреть, что может быть с вашей проблемой. – idjaw
Вам нужно вести ведущие «http (s)»? – Bahrom
Да, мне придется @Bahrom –