1

I am trying to find replace thousands of strings in code - form.controls['property'] with form.get('property') where property is a variable. So far I got find expression .controls\['\w+'\] with replace expression .get\('\w+'\) but VSCode is replacing .controls['products'] with .get\('\w+'\) for string productForm.controls['products'].controls.length. I need to replace it with productForm.get('products').controls.length Any ideas how to fix it? Thanks!

Manish Jain
  • 9,569
  • 5
  • 39
  • 44

1 Answers1

1

Parentheses () capture a group. Money sign $ accesses a group by index.

.controls\['(\w+)'\]

.get('$1')

This is the result in VS Code:

the regex successfully finds and replaces the target text.

See also: What flavor of Regex does Visual Studio Code use?

Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467