$reg = '/^[^/]+?(/[^/]+?){2}[^/]*/'; $str = 'admin/associator/edit'; preg_match($reg,$str,$match); var_dump($match[0]);