Regular expression to find URLs within a string

前端 未结 27 1763
被撕碎了的回忆
被撕碎了的回忆 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:45

    IMPROVED

    Detects Urls like these:

    • https://www.example.pl
    • http://www.example.com
    • www.example.pl
    • example.com
    • http://blog.example.com
    • http://www.example.com/product
    • http://www.example.com/products?id=1&page=2
    • http://www.example.com#up
    • http://255.255.255.255
    • 255.255.255.255
    • http:// www.site.com:8008

    Regex:

    /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/gm
    

提交回复
热议问题