optimized url regex and code