Regex for url validation with parts capturing

前端 未结 2 571
谎友^
谎友^ 2021-01-19 11:11

Can a single regex be used to valdate urls and match all the parts, I have been working on one and what I have come up with so far is:

(?:(?P[a         


        
2条回答
  •  不知归路
    2021-01-19 11:42

    Modified version of mingfai's regular expression:

    /^((?Phttps?|ftp):\/)?\/?((?P.*?)(:(?P.*?)|)@)?(?P[^:\/\s]+)(?P:([^\/]*))?(?P(\/\w+)*\/)(?P[-\w.]+[^#?\s]*)?(?P\?([^#]*))?(?P#(.*))?$/
    

提交回复
热议问题