Optimized regex and used test method in hasValidUrl method