URL Regex (Regular Expression)

August 7, 2012

I have been researching and fine tuning a regular expression to find http, https and ftp addresses within the body of text so that they can be shortened and automatically linked in PHP code.

This is my latest regex which seems to work OK:

((http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9:\-\._\?\,\'/\\\+&%$#\=~])*[^\.\,\)\(\s])

 Appreciation:

  • RegexBuddy : Software for creating, testing and using regular expressions.
  • EditPad Pro : A powerful text editor especially for programming.
Share this:
About Bharat Karavadra

"I research and share leading-edge information, tools and exercises to help people transform and heal their life situations."

Share your thoughts

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
Bharat Karavadra