Regular expression to find URLs within a string

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

    Here a little bit more optimized regexp:

    (?:(?:(https?|ftp|file):\/\/|www\.|ftp\.)|([\w\-_]+(?:\.|\s*\[dot\]\s*[A-Z\-_]+)+))([A-Z\-\.,@?^=%&:\/~\+#]*[A-Z\-\@?^=%&\/~\+#]){2,6}?
    

    Here is test with data: https://regex101.com/r/sFzzpY/6

提交回复
热议问题