For example
$xcontext.user -> Xwiki.user.trim('Xwiki')
"XWiki." How can I remove the expression? I tried this but it did not work.
Just extract the page name (i.e. profile page name) from the current user's reference. It's the best way and you avoid String manipulation:
$xcontext.userReference.name