1

How can I use a custom Visual Studio Code snippet to remove slashes (/), along with other characters, from a selected piece of code?

When I've created a new object to keybindings.json, it only recognized the plus sign (+) :

   {
      "key": "ctrl+8",
      "command": "editor.action.insertSnippet",
      "args": {
         "snippet": "${TM_SELECTED_TEXT/['+','\/']//gi}"
      },
   },

Thanks!

1 Answers1

0

You need to use

"${TM_SELECTED_TEXT/[+\\/]+//g}"

Here, the [+/]+ character class matches + or / one or more times.

Note the syntax: you cannot use an array of string literals inside the regex part. You need to escape / because the pattern is separated from replacement and flags with a / delimiter char. To properly escape / here, you need to use double backslash, as the \ char can be used in this environment to define string escape sequences, and thus to define a single literal backslash you need to use two.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563