How to Get a part of URL and put in shortcode?

This should work:

function get_name() {
    $url = "http://domain.com/author/peter";

    if (preg_match("/author/", $url )) {
        $lastSlash = strrpos( $url, "https://wordpress.stackexchange.com/");
        return substr( $url, $lastSlash, strlen($url));
    }
}

This will return everything after the last slash.