I made regex and I applied it within this function. I tested on regex engine and its working fine but I don't know why it does not within this JS Function
function validURL(str) {
var pattern = new RegExp(
'^((https?)://)(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z]'+
'[A-Za-z0-9\-]*[A-Za-z0-9])(:[0-9]*)?'+
'(?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+=&;%@\/%\.\w]*)#?'+
'([\-\+=&;%@\/%\.\w]*)$',"i" );
var isValid = pattern.test(str);
return isValid;
}
Input: https://www.xml.com/pub/a/2003/09/17/stax.html#id=_abc
Output Result: it gives me syntax errors. Can anyone advise me with a reason?
Thanks in advance
Best regards