0

How can I replace multiple string contents to empty strings in a JSON file using find/replace in VS Code? I assume regex can help here but I'm not clear on how to use it in the find/replace dialog. I've checked other questions on SO and haven't found a suitable answer.

Example

{
   "value":"93827364"
},
{
   "value":"72653423"
},
{
   "value":"37369425"
},
{
   "value":"59026204"
}

Search term

Find:     ?
Replace:  "value":""
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Paul Redmond
  • 3,276
  • 4
  • 32
  • 52

1 Answers1

3

If you don't care about the values, you can use the RegEx (?<="value":")[^"]+(?=")

  • (?<="value":") is a positive lookbehind, it makes sure there is "value":" before your match

  • [^"]+ matches anything but a " 1 or more times

  • (?=") is a positive lookahead, it makes sure there is " after your match

Replace with nothing. Don't forget to enable regular expressions on the search on VSC (Alt + R by default).

Demo.

Find:     (?<="value":")[^"]+(?=")
Replace:  

If your VSC doesn't accept lookarounds, you can use "value":"[^"]+"

And replace with "value":""

Demo.

Zenoo
  • 12,670
  • 4
  • 45
  • 69