It depends on what you mean by "get" the hash anchor, but I'm assuming you're trying to get it in either PHP, Twig, or JavaScript.
It is physically impossible to get the #anchor
part via PHP, since PHP never has access to that information. This SO thread describes the issue.
If you're trying to access the #anchor
in Twig, you're probably out of luck there too. Twig is just a PHP parser, so you've essentially got the same problem.
All you can do is access it via JavaScript. In which case, there is nothing Craft-specific about it (see linked SO thread).