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
CodePudding user response:
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/}/}"
CodePudding user response:
It looks like i was writing the grammer incorrect adding a trailing slash / the correct way is below
${TM_FILENAME_BASE/(.).\.[model] $/${1:/capitalize}/};"