Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Snippets: Format File Name from my_file_name to MyFileName

I am creating custom snippets for flutter/dart. My goal is to pull the file name (TM_FILENAME_BASE) remove all of the underscores and convert it to PascalCase (or camelCase).

Here is a link to what I have learned so far regarding regex and vscode's snippets. https://code.visualstudio.com/docs/editor/userdefinedsnippets

I have been able to remove the underscores nicely with the following code

    ${TM_FILENAME_BASE/[\\_]/ /}

I can even make it all caps

    ${TM_FILENAME_BASE/(.*)/${1:/upcase}/}

However, it seems that I cannot do two steps at a time. I am not familiar with regex, this is just me fiddling around with this for the last couple of days.

If anyone could help out a fellow programmer just trying make coding simpler, it would be really appreciated!

I expect the output of "my_file_name" to be "MyFileName".

like image 756
mrgnhnt96 Avatar asked Oct 30 '25 12:10

mrgnhnt96


1 Answers

It's as easy as that: ${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}

like image 105
Igor Kharakhordin Avatar answered Nov 01 '25 06:11

Igor Kharakhordin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!