Regular expression to find URLs within a string

前端 未结 27 2124
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 14:18

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

27条回答
  •  盖世英雄少女心
    2020-11-22 14:55

    It is just simple.

    Use this pattern: \b((ftp|https?)://)?([\w-\.]+\.(com|net|org|gov|mil|int|edu|info|me)|(\d+\.\d+\.\d+\.\d+))(:\d+)?(\/[\w-\/]*(\?\w*(=\w+)*[&\w-=]*)*(#[\w-]+)*)?

    It matches any link contains:

    Allowed Protocols: http, https and ftp

    Allowed Domains: *.com, *.net, *.org, *.gov, *.mil, *.int, *.edu, *.info and *.me OR IP

    Allowed Ports: true

    Allowed Parameters: true

    Allowed Hashes: true

提交回复
热议问题