PHP regex for validating a URL

后端 未结 4 1685
囚心锁ツ
囚心锁ツ 2020-12-02 00:38

I\'m looking for a decent regex to match a URL (a full URL with scheme, domain, path etc.) I would normally use filter_var but I can\'t in this case as I have to support PHP

4条回答
  •  [愿得一人]
    2020-12-02 01:21

    !(https?://)?([-_a-z0-9]+\.)*([-_a-z0-9]+)\.([a-z]{2,4})(/?)(.*)!i
    

    I use this regular expression for validating URLs. So far it didn't fail me a single time :)

提交回复
热议问题