In a previous article about VS Code, , I had a question that prompted me to create this article so that I can remember what I did ... Search-and-Replace using RegEx The Question What if I need to replace something with ? For example, replace with , the regex to search is easy, the problem is the replacement. I (have tried this) with (and) it does not work properly. So how do we go about it? $ $var $this->var = $var $this->$1 = $$1 The Solution The solution, as I see it is actually in two parts. First, we need to properly select the content for replacement. Then, second, we need to define the replacement, ... accounting for the dollar-sign Selecting the Content When I started breaking down the question in my head, I saw some content like the following ... $ ; $content; $question; var ... the assumption being that this should be changed into ... $ -> = $ ; $ ->content = $content; $ ->question = $question; this var var this this So, this means I need to capture the text after the dollar sign. As stated in the question, this is pretty straight forward. There are many ways to do this. I chose ... \$([a-zA-Z0 ]*) -9 Replacing the Content The dollar-sign after the equal sign seems to be where the main concern of the question comes from. I will admit that it took me a few minutes to get my head around the issue of escaping it. Original Attempt First, I tried this replacement RegEx ... $ ->$ = $$ this 1 1 ... this is shown in the question and makes sense; however, the result is ... $ -> = $ this var 1 Escaping the Dollar-Sign ... then, I tried escaping the dollar-sign after the equal-sign ... $ ->$ = \$$ this 1 1 ... however, the result is not quite what I expected ... $ -> = \$ this var var Proper Escaping of the Dollar-Sign While this is closer, there is clearly something wrong with this approach. I then started searching for how to properly escape the dollar-sign in a RegEx Search-and-Replace. I found the following ... Stack Overflow Answer The Solution And, here's the answer ... $ ->$ = $$$ this 1 1 ... try it out, it works! Also published on Dev.to