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

View Comments to “A really loose regex for matching URLs”

  1. Rusty says:

    Might want to account for https:

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

  2. tiffany says:

    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.

blog comments powered by Disqus