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

  • http://rustytanton.com/ Rusty

    Might want to account for https:

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

  • http://rustytanton.com Rusty

    Might want to account for https:

    /(http|https):\/\/[\-\.\/\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.

  • 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.