Pages

Jul 5, 2013

Regex to detect URLs with or without protocol name

Regex to detect URLs with or without protocol name

((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)

matches:
http://www.google.com
www.google.com
ftp://google.com
https://www.google.com