You can use the same Regular Expression-based method that this jQuery linkify plugin uses, just implemented in PHP instead of JavaScript.
You may need to tweak this a bit, but it should look something like this (boilerplate for TWIG plugin based on http://symfony.com/doc/current/cookbook/templating/twig_extension.html):
class LinkifyExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
'linkify' => new \Twig_Filter_Method($this, 'linkifyFilter', array('pre_escape' => 'html', 'is_safe' => array('html'))),
);
}
public function linkifyFilter($text)
{
$pattern = "/\B#(\w+)/";
$replacement = "<a href=\"HASHTAG_BASE_URL/$1\">#$1</a>";
return preg_replace($pattern, $replacement, $text);
}
public function getName()
{
return 'linkify_extension';
}
}
After you have registered your extension, you can use it like this:
{{post.content | linkify}}