You need to use \1 instead of $1, see perlre.
You may also want to move the \s? out of the capture group.
Update: Plus, what LanX said about using a lookahead!
In reply to Re: Regex: remove non-adjacent duplicate hashtags (updated)
by haukex
in thread Regex: remove non-adjacent duplicate hashtags
by element22
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |