regex to find url in a text

前端 未结 6 468
星月不相逢
星月不相逢 2020-11-28 14:19

I have to find the first url in the text with a regular expression:

for example:

I love this website:http://www.youtube.com/music it\'s fantastic
         


        
6条回答
  •  误落风尘
    2020-11-28 14:44

    This might work->

    \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
    

    Found it somewhere

    Will find links ->

    http://foo.com/blah_blah/

    (Something like http://foo.com/blah_blah)

    http://foo.com/blah_blah_(wikipedia)

    Hope this works....

提交回复
热议问题