I have written regex to validate URL which could be either like
example.com
www.example.com
http://www.example.com
when creating a regex for strict matching, you must make it sure it begins with '^' and finishes with '$'. Otherwise, the regex will see if it finds a substring which matches.
However, using a regex to match an URL is error prone : better rely on existing frameworks doing it better (there are a lot of potential traps in url, like parameters, unkown domains, url containing ip instead of domain....)