Encapsulate results in div tags
Sure, use String.replace. As an added bonus, it doesn't fail when there is no match:

'&lt;div&gt;this is a $test&lt;/div&gt;'.replace(/(\$\w+)/g, '&lt;div&gt;$1&lt;/div&gt;')