How to get a specific string from a url

I believe you should be able to use this:

global $post;
$page_slug = $post->post_name;

Where $page_slug is the variable you’re looking for. This has a pretty good explanation of why that works: https://blog.wplauncher.com/get-current-page-slug-wordpress/