Search code examples
regexflutterdartvisual-studio-codecode-snippets

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".


Solution

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