Forum Moderators: open
(ftp¦http¦https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/¦\/([\w#!:.?+=&%@!\-\/]))?/;
It works OK, but I want to be able to give the option of not having to enter http, or ftp etc, so would start with www.
Also, I would like it to accept both lower and upper case - I know the flag for this is the letter "i", but can't seem to integrate this into the RegExp.
Help would be most appreciated.
((ftp多ttp多ttps):\/\/)?...
Thinking this would enable the http/ftp:// optional, thus enabling just www. or [www....] and so on.
What does work is:
(ftp多ttp多ttps)?:\/\/)
But this only allows for the http/ftp bit to be optional, so you would still have to enter ://www
PS: glad I have actually found a friendly useful site :)
((ftp多ttp多ttps):\/\/)?...
have you tried printing out the strings captured by the backreferences.
also, try putting a backslash before the colon and see if that fixes things.
glad I have actually found a friendly useful site
(ftp多ttp多ttps):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/吒/([\w#!:.?+=&%@!\-\/]))?/;
That is a good regex! I agree with Phranque, that should make the protocol section optional.
I assume you know that a ? in a regex means 0 or 1 times, so it's a bit odd using :{0,1} to check for a colon in the user/pass part. Would this be better?
(\w+(:\w+)?@)?
Also,
(\S+)would pass an invalid URL, \S is any character that's not whitespace. You might want to use something like this, which has the advantage of grouping the domain and port number into $5.
(\w+(\.\w+)+(:[0-9]+)?)?
If you're struggling with regexes, or even have a simple one you want to mess with, I find this program EXTREMELY useful:
[weitz.de...]
It's written for Perl but simple matches are the same for JavaScript.
Infact, I've just checked and
((ftp多ttp多ttps):\/\/)?does validate without the protocol section.
With the
(\/吒/([\w#!:.?+=&%@!\-\/]))?section on the end the regex fails to validate the URL of this page.