I'm going mad with this regex in JS:
var patt1=/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*?(:[0-9]+)?(\/)?$/i;
If I give an input string like "http://www.eitb.com/servicios/concursos/516522/" this regex it's supossed to return NULL, because there are a "folder" after base URL. It works in PHP, but not in Javascript, like in this script:
<script type="text/javascript">
var str="http://www.eitb.com/servicios/concursos/516522/";
var patt1=/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*?(:[0-9]+)?(\/)?$/i;
document.write(str.match(patt1));
</script>
It returns
http://www.eitb.com/servicios/concursos/516522/,,/516522,,/
The question is: why it is not working? How to make it work?
The idea is to implement this regex in another function to get NULL when the URL passed is not in the correct format:
http://www.eitb.com/ -> Correct http://www.eitb.com/something -> Incorrect
Thanks