Use this:
str.replace(/\${2}(.*?)\${2}/g, "<I>$1</I>");
\${2} matches two $ characters
(.*?) matches your string to be wrapped
\${2} same as above
/g matches globally
jsFiddle
If you wanted something in jQuery:
$("#txt").val().replace(/\${2}(.*?)\${2}/g, "<I>$1</I>");
Markup:
<textarea id="txt">I'm $$Zach$$</textarea>
jsFiddle
Wrap it in a function for best use:
var italics = function (str) {
return str.replace(/\$\$(.*?)\$\$/g, "<I>$1</I>");
}
italics($("#txt").val());
Seems like you want to make a syntax similar to Markdown. Why not just use a Markdown parser for your fields instead of reinventing the wheel?
Showdown JS is actively developed and you get the same Markdown syntax as with any other markdown syntax.