在 VSCode 片段中,如何将另一个用户定义变量的值大写? [英] In VSCode snippets, how can I capitalize the value of another user-defined variable?
问题描述
我在 VSCode 中尝试制作代码片段并了解一些新的正则表达式替换语法.
I'm in VSCode trying to make snippets and get my head around some of the new regex replacement syntax.
我想做的是根据文件名填充模板的部分内容.我可以去掉不需要的扩展名,但我不能在下一个变量中使用相同的值.
What I want to do is populate parts of my template based on the filename. I can strip the unwanted extensions okay, but I can't capitalize the same value in the next variable.
我有这两行:
<代码>"@Controller('/${1:${TM_FILENAME_BASE/(.*)\\.controller/$1/}}')","导出类 ${1/(.*)/${1:/capitalize}/}Controller {",
第一个去除文件名并将值捕获为模板的 $1.在第二行中,我尝试使用 $1 中的值并通过大写过滤器运行它.
The first strips filename and captures the value as $1 for the template. In the second line, I'm trying to use the value from $1 and run it through the capitalize filter.
我尝试过的一切都没有奏效,尽管用头敲击键盘感觉很好.
Nothing I've tried works, although bashing my head against the keyboard feels kind of nice.
有人破解了吗?
推荐答案
这至少从 v1.25 开始:
This works at least as of v1.25:
"@Controller('/${TM_FILENAME_BASE/(.*)\\.controller/$1/}')",
"export class ${TM_FILENAME_BASE/(.*)$/${1:/capitalize}/}Controller {",
产量:
@Controller('/myGlobalSnippets')
export class MyGlobalSnippetsController {
这篇关于在 VSCode 片段中,如何将另一个用户定义变量的值大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!