var url_pattern = new RegExp("(?:http| https)://(www.|.*)someurlhere[.]com/\d\d\d\d/\d\d/\d\d/.*/", "i");
var url=window.location; //or could be document.URL both don't work
url.match(url_pattern);
why does it return null, or undefined but when i throw the Regex into a check it works perfect and i just want to make sure the URL matches
You have issues with your slashes and an extra space before
httpsand some period characters not escaped properly either.When using the
new RegExp("string")format, you have to double escape any backslash. It’s much easier to use the/regexhere/syntax because you don’t have to double escape the backslash used in so many regex rules.Also, a string has a regex method called
.match(). The regex itself has a method called .test()or.exec(). I would suggest this:If you want to stay with the other way of declaring it, you would escape every backslash like this: