JavaScript Regex to match a URL in a field of text

前端 未结 8 1282
一向
一向 2020-12-01 02:01

How can I setup my regex to test to see if a URL is contained in a block of text in javascript. I cant quite figure out the pattern to use to accomplish this



        
8条回答
  •  庸人自扰
    2020-12-01 02:40

    try this worked for me

    /^((ftp|http[s]?):\/\/)?(www\.)([a-z0-9]+)\.[a-z]{2,5}(\.[a-z]{2})?$/
    

    that is so simple and understandable

提交回复
热议问题