Search code examples
jsonregexcode-snippetsebnfvscode-snippets

How to build complex vs code snippet variable transforms?


I'm trying to write a code snippet for vs code that takes a given file name, removes a piece of the name and capitalizes the first letter. For example

Input: example.model.js

Output: Example

Output im getting: ${TM_FILENAME_BASE/(.*).[model]+$//capitalize//}

I'm able to remove the trailing half of the file name with the following string

"${TM_FILENAME_BASE/(.*)\\.[model]+$/$1/}"

I tried to take this a step further with the following but it doesn't seem to work.

 "${TM_FILENAME_BASE/(.*)\\.[model]+$/${1:/capitalize/}/}"

Based on the documentation i'm not sure where I'm going wrong. https://code.visualstudio.com/docs/editor/userdefinedsnippets#_transform-examples

Any ideas on what I'm missing here? Also are there any tools that could help build these kinds of complex expressions?

Thanks


Solution

  • It looks like i was writing the grammer incorrect adding a trailing slash / the correct way is below

    ${TM_FILENAME_BASE/(.).\.[model]+$/${1:/capitalize}/};"