1 min read

一枚无语的正则

刚刚看CodeIgniter源代码,2.2.0版本,看到这么个函数:

function system_url()
{
    $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
    return $this->slash_item('base_url').end($x).'/';
}

愣了好一会儿才反应过来,其实就是trim(BASEPATH, ’/‘)吧?