6

So... Has anyone already found the perfect URL validation regex?

Comments
  • 12
    /_^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS/

    The dude who came with this solution must be in an hospital somewhere.
  • 1
    @Drillan767
    Why https|ftp,

    So we have ftp but no http?

    Sftp?
  • 0
    @Drillan767 where did u find it?
  • 1
    @D--M https?|ftp matches http, https and ftp
  • 2
    @D--M sftp is like ftp but via ssh. Like a scp but FileZilla can handle it and connect through the 22 port.
  • 1
    @fastidio I googled the last 3 words in your question, and clicked the 3rd or 4th link, that almost has the same question word to word :D
  • 2
    @fastidio @Drillan767

    Ignore me, i am retarded.

    Rofl, not sure if thats a bad thing
  • 0
    @Drillan767 I've searched this many times, but all answers have errores.

    This is the best approach:

    https://mathiasbynens.be/demo/...
  • 0
    @fastidio Fun fact : the long ass answer I gave you is a copy/paste of the last regex given (502 chars) :D
  • 1
    @Drillan767 haha, look at @scoottgonzales's answer, 1347 characters 😵 I think it's the best solution.
  • 1
    @fastidio I should have pasted this instead :'D
  • 1
    @Drillan767 And here I am, getting spooped by telephonenumber regexing.
Add Comment