How to get the part of URI and pass it to as a argument? I can access current path using method \Drupal::request()-&gt;getRequestUri(); as shown below.

    function bartik_preprocess_node(&amp;$variables) {
        $variables['current_path'] = \Drupal::request()-&gt;getRequestUri(); 
    }


Now, this is giving me path, /drupal8101/user/1 if I am on the user1 profile page. (Complete path of site:http://localhost:8888/drupal8101/user/1), which is working right. 

So, if I want to put any argument in the twig file, it is fulfilling only for /drupal8101/user/1, that is understood.

    {% if current_path == '/drupal8101/user/1'%}
       .............
    {% endif %}


In above case it is working fine, But what can I do to get that condition worked for all users like /drupal8101/user/*.

In short, I want following kind of thing, 

    {% if current_path == '/drupal8101/user/*'%}
       .............
    {% endif %}
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.