DEV Community

Discussion on: VS Code: Search-and-Replace Regex

Collapse
 
rfornal profile image
bob.ts

OK. I see a couple of things going on here.

First, you state you are using '$var', for replacement, this should be '(\$[a-zA-Z]*)'.

  • The parens allow for the selection as $1
  • The backslash allows VS Code to correctly find '$var' in the content as REGEX.

Second, to use '$this->$1 = $$1' as a pattern for replacement ...

  • The selection above in my first response would need changed to something like this '\$([a-zA-Z0-9]*)' to allow for selection of text that starts with a dollar sign.
  • The replacement pattern should be changed to '\$this->=>$1 = $$$1'. The dollar sign in the replacement is "escaped" using the double-dollar-sign (see HERE)