Tiffany B. Brown

a mish-mosh of stuff

A really loose regex for matching URLs

Not recommended for validating URLs, but it will find them. The g flag is JavaScript specific and indicates that the matching should be global.

/http:\/\/[\-\.\/\w]{1,256}(|\/)/gi

  • tiffany
    Yes. I also left out FTP and most other protocols too. That was deliberate. This was a quick-and-dirty RegEx that I used for a specific purpose. I published it here because I wanted to save it somewhere and remember where I saved it.
  • Might want to account for https:

    /(http|https):\/\/[\-\.\/\w]{1,256}(|\/)/gi
blog comments powered by Disqus
previous post: On the perils of a backchannel
next post: It’s not Islam. It is us.