0👍
You need to make multiple changes to make it work:
- There is no need to add
+
quantifiers in\/\/
. - No need to add
\w
in[w\d]+
. Since you are matchingwww
orw3
something like this so\w
is allowed means you are allowing alphanumeric and underscore also. - Add
$
at the end of the regex, match only if it matches completely
var regex = /^(http|https):\/\/[w\d]+\.[\w](\/[\w\d]+)?$/;
const str = "http://www.google";
console.log(regex.test(str));
Source:stackexchange.com