Regular expression to find URLs within a string

Does anyone know of a regular expression I could use to find URLs within a string? I've found a lot of regular expressions on Google for determining if an entire string is a URL but I need to be able to search an entire string for URLs. For example, I would like to be able to find www.google.com and http://yahoo.com in the following string:

Hello www.google.com World http://yahoo.com

I am not looking for specific URLs in the string. I am looking for ALL of the URLs in the string which is why I need a regular expression.

72
задан AeroX 30 July 2015 в 15:50
поделиться

1 ответ

Это просто просто.

Использование этот шаблон: \b((ftp|https?)://)?([\w-\.]+\.(com|net|org|gov|mil|int|edu|info|me)|(\d+\.\d+\.\d+\.\d+))(:\d+)?(\/[\w-\/]*(\?\w*(=\w+)*[&\w-=]*)*(#[\w-]+)*)?

Это соответствует любой ссылке, содержит:

Разрешенные протоколы: http, https и ftp

Позволенные Домены: *.com, *.net, *.org, *.gov, *.mil, *.int, *.edu, *.info и *.me ИЛИ разрешенные порты IP

: верный

Позволенные Параметры: верный

Позволенные Хеши: верный

0
ответ дан 24 November 2019 в 12:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: