How to get the part of URI and pass it to as a argument?
Probably what you want to do, is to make some logic for the route name instead of the path.

So the user profile page has the route named entity.user.canonical which has the path /user/{user}. So if you compare on the route name, you will get all user profile pages. This also makes it very easy to limit your selection so you can do something different for the user edit page etc/

Anyways to get the current route you can do 

$variables['current_route'] = \Drupal::routeMatch()-&gt;getRouteName();


\Drupal::routeMatch() is a shortcut for the current_route_match service.