Please, help me to fix this regular expression to make it workable in JavaScript:
Code:
var r = /^((((ht|f)tp(s?))\://)|(/{1}))?((([a-zA-Z0-9_\-]{2,}\.)+[a-zA-Z]{2,})|((?:(?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(\.?\d)\.)){4}))(:[a-zA-Z0-9]+)?(/[a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~]*)?$/;
In fact, here it works fine, but only if i choose .NET Regex Engine. When i'm using JavaScript one, it doesn't even run.
What have i tried is to screen this place "...//..." with "...\/\/...", but it doesn't help.
You have to escape no only the two first slashes but the followings...
It would be good to know what it has to make (http or ftp with a possible s but after (\/{1}) ???) rather than try to guess it !
I see four parts (I add \ before the javascript delimiter / for regular expressions) :
1/ ^(((ht|f)tp(s?))\:\/\/)?
2/ ((([a-zA-Z0-9_\-]{2,}\.)+[a-zA-Z]{2,})|((?: (?:25[0-5]|2[0-4]\d|[01]\d\d|\d?\d)(?(\.?\d)\.)){4})) with a green alternative
3/ (:[a-zA-Z0-9]+)?
4/ (/[a-zA-Z0-9\-\._\?\,\'\/\\\+&%\$#\=~]*)?$
The first one is optional ( )?
The second is made with
at least two alphanumeric characters, followed by a point and at least two alphabetic characters
or :
25 followed by a number included between 1 and 5,
2 followed by a number included between 0 and 4 and a digit,
0 or 1 followed by two digits,
one or two digits,
followed by something like (?(\.?\d)\.) which make not sense the parenthesis cannot be optional. (?: ) would be a non-capturing sub-patterns ?
//...
The fourth part is also curious with a amp in a class which contains all alphabetic characters...
If you want to use an alternative with /folder or /other you have to specify the part to replace ...
Bookmarks