match url pattern in php using regular expression

前端 未结 8 1681
别那么骄傲
别那么骄傲 2020-12-01 18:32

I want to match a url link in wall post and replace this link with anchor tag, for this I use the regular expression below.

I would like the match 4 types of url:

8条回答
  •  离开以前
    2020-12-01 19:13

    I looked around and didn't see any that were exactly what I needed. I found this one that was close, so i modified it as follows:

    ^((([hH][tT][tT][pP][sS]?)\:\/\/)?([\w\\-]+(\[\w\.\&%\$\-]+)*)?((([^\s\(\)\<\>\\\"\.\   [\]\,;:]+)(\.[^\s\(\)\<\>\\\"\.\[\]\,;:]+)*(\.[a-zA-Z]{2,4}))|((([01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}([01]?\d{1,2}|2[0-4]\d|25[0-5])))(\b\:(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)\b)?((\/[^\/][\w\.\,\?\'\\\/\+&%\$#\=~_\-]*)*[^\.\,\?\"\'\(\)\[\]!;<>{}\s\x7F-\xFF])?)$
    

    check it out on debuggex.

提交回复
热议问题