JavaScript Regex to match a URL in a field of text

前端 未结 8 1288
一向
一向 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:47

    The trouble is that the "-" in the character class (the brackets) is being parsed as a range: [a-z] means "any character between a and z." As Vini-T suggested, you need to escape the "-" characters in the character classes, using a backslash.

提交回复
热议问题