I know that the question is related to PHP, but if anyone have any problems with escaping $ you can alternatively wrap it in character list like this: [$]\w+[$] .
$
[$]\w+[$]