How do you modify the following regex:
String URLpattern = "((https?|ftp|gopher|telnet|file|Unsure|http):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)"
with one that takes into account ALL the following URL forms?
http://www.website.com
https://www.website.com
www.website.com
website.com
http://website.com
https://website.com
EDIT: There are a bunch of already proposed solutions to the problem. I can list some of them:
- Regular expression to match URLs in Java
- Regex to matches a url with or without http in java (nice since explained, however not working in my code)
- Regular Expression, match url without "http://" and any other "/"
However, although I tried all of them too, none of them is proposing an explanation of how and why the expression works. Thus, whenever there is a malfunctioning (and to me, a malfunctioning was happening in urls in the form website.com
and http://website.com
), it becomes difficult for newbies (like me ;) ) to apply any modification or understand what is going on when there is a failure.
A well explained solution is always better than a solution made by others and not replicable in the next time =)