Home > Enterprise >  Change all php variable from underscore case to camelCase using regex
Change all php variable from underscore case to camelCase using regex

Time:12-19

I found a neat vscode way to convert underscores to camelCase but it will affect all words. I want to limit the search to words with $ at the beginnig. With what I searched, I need to add ^$ before the string I want to match but unable to properly work it. Below is the way I found in this link

1. Press CTRL-H ( ⌥⌘F on Mac ).
2. Press ALT-R ( ⌥⌘R on Mac ).
3. Type _([a-zA-Z]).
4. Press TAB and type $1.
5. Press ALT-ENTER ( ⌥ENTER on Mac ).
6. Press F1 and type upper, then press ENTER.
7. Press CTRL-ALT-ENTER ( ⌥ENTER on Mac ).

meaning change all $is_data to $isData while words like _construct are unchanged.

CodePudding user response:

You can find all words starting with starting $ and min one underscore using this \$\w*_\w* and replace with $1${2:lower}.

CodePudding user response:

Just change _([a-zA-Z]) to:

\B_([a-zA-Z])

To make sure we have a word character before matching _.

RegEx Demo

  • Related