Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change lower case to upper using regular expressions in Visual Studio Code

I'm using Visual Studio Code 1.14.2, and I'm trying to change name of variables to camelCase eg. set_nominal_wavelength to setNominalWavelength.

Regular expression: _([a-z])

Replace: \U$1\E

does not work. Any idea how to achieve it?

like image 671
Maciej Haj Avatar asked Aug 02 '17 12:08

Maciej Haj


People also ask

How do I change case in VSCode?

Command Palette: CTRL + SHIFT + p (Mac: CMD + SHIFT + p ) type >transform pick upper/lower case and press enter.

How do you write regular expression in VSCode?

VSCode usage Vscode has a nice feature when using the search tool, it can search using regular expressions. You can click cmd+f (on a Mac, or ctrl+f on windows) to open the search tool, and then click cmd+option+r to enable regex search. Using this, you can find duplicate consecutive words easily in any document.

What kind of regex does VSCode use?

VSCode is using JavaScript-based regex engine, but it is not the same. You cannot use named capturing groups there. There is no specific documentation on the regex used in VSCode. However, if you have a look at the source code, you will see lots of JS code around.


1 Answers

There is a workaround:

  1. Open Replace dialog and enter regex: _([a-z])
  2. Then move focus to the editor area and press Ctrl+F2 ("Change All Occurrences")
  3. Then change case of selection (Ctrl+P >upper)
  4. Then press Left Arrow key and press Delete key
like image 51
Dmitry Sokolov Avatar answered Sep 25 '22 17:09

Dmitry Sokolov