I want to tranform filename-with-dashes.md
to Filename with dashes
in a Vscode snippet
To be precise, I want to populate the field "title"
in this snippet, from a filename similar to firt-post-ever.md
and get First post ever
:
"FrontMatter": {
"scope": "markdown",
"prefix": "frontmatter",
"body": [
"---",
"title: '${TM_FILENAME_BASE/^([^-]*)-([^.]*).*/${1:/pascalcase} ${2:/capitalize}/}'",
"draft: true",
[...]
What I have so far:
This regex changes filename-with-dashes.md
to Filename with-dashes
(← I still need to remove the dashes in the end):
${TM_FILENAME_BASE/^([^-]*)-([^.]*).*/${1:/pascalcase} ${2:/downcase}/}
Resources I checked:
- https://code.visualstudio.com/docs/editor/userdefinedsnippets#_grammar
- vscode snippet - multiple regex transformation filepath+filename
- VSCode Keybinding Snippet: Use TM_SELECTED_TEXT to Remove All Slashes From A Selected String
- VSCode chaining regex transforms in a snippet
- Transform and regex in Code Snippets in VSCode - Docs
Unfortunately, these pages wasn't enough to find a proper answer (I can't understand the regex syntax, despite heavy effort I can't get it..) Any hint?
Notes:
- only the first letter of the whole title must be uppercase
- the filename may contain dots (example: notes-for-dev.to-update-2022.md).
In such case only the file extension must be stripped