B4dmonkey
B4dmonkey

Reputation: 132

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

Upvotes: -1

Views: 183

Answers (2)

B4dmonkey
B4dmonkey

Reputation: 132

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

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

Upvotes: 1

pavi2410
pavi2410

Reputation: 1285

With this regex (.*)\\.[model]+$, (.*) captures the whole word.

For eg, it will capture example in example.model.js and thus, capitalize it as EXAMPLE

You need to capture only the first character like so:

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

Upvotes: 0

Related Questions