我正在 中编写自定义代码段VSCode 帮助我轻松定义自定义类方法。我需要能够输入字符串 'formatted_like_this' 并让正则表达式在某些地方转换该字符串,使其成为 'FormattedLikeThis'?
要在 php.json 中编写的自定义代码段:(有关我正在努力的地方,请参阅此处的“需要使用正则表达式帮助”)
"New Custom Class Method For Variable": {
"prefix": "contcmpffv",
"body": [
"protected $$1 = null;",
"public function get${NEED HELP WITH REGEX HERE}()",
"{",
"\t$0",
"}"
],
"description": "Controller Class Method Public Function For Variable"
}
我想要的工作流程:
1. 输入 contcmpffv
2. 在提示匹配代码段时按 Enter
2. 代码片段提示我 1 美元
所需的输出(在提示输入 $1 时输入“test_input_string”):
protected $test_input_string = null;
public function getTestInputString()
{
*cursor resolves here (due to $0)*
}
最佳答案
尝试:
"body": [
"protected $$1 = null;",
"public function get${1/(.*)/${1:/pascalcase}/}()",
"{",
"\t$0",
"}"
],
它使用未记录的
pascalcase
转换 - 已经存在一段时间了。在这种情况下,它会为您完成所有工作。如果没有
pascalcase
,这就是你可以使用的。 :"public function get${1/([^_]*)_*/${1:/capitalize}/g}()",
关于json - VSCode 片段,将由下划线分隔的小写字符串转换为 CamelCase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59144915/