Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
191
rated 0 times [  194] [ 3]  / answers: 1 / hits: 41765  / 14 Years ago, thu, november 25, 2010, 12:00:00

I'm looking for a regex that accept urls like these:



http://www.example.com
www.example.com


This is what I have so far, but it regex doesn't match URLs without http:// or https://, or ftp://:



regexp = /(ftp|http|https)://(w+:{0,1}w*@)?(S+)(:[0-9]+)?(/|/([w#!:.?+=&%@!-/]))?/;


How can I make the protocol optional?


More From » regex

 Answers
14

Make the (ftp|http|https):// part optional:



((ftp|http|https)://)?

[#94850] Monday, November 22, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;