【发布时间】:2019-12-02 18:41:25
【问题描述】:
我正在 VSCode 中编写自定义 sn-p 来帮助我轻松定义自定义类方法。我需要能够输入一个字符串 'formatted_like_this' 并让正则表达式在某些地方转换该字符串,使其变为 'FormattedLikeThis'?
要在 php.json 中编写的自定义 sn-p:(在我遇到困难的地方请参阅“此处需要 REGEX 帮助”)
"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.当提示匹配sn-p时按回车 2. sn-p 提示我 1 美元
所需的输出(在提示输入 $1 时输入“test_input_string”):
protected $test_input_string = null;
public function getTestInputString()
{
*cursor resolves here (due to $0)*
}
【问题讨论】:
-
我不确定 Visual Studio 自定义 sn-ps,但在 javascript 中这样的东西可以工作:
('formatted_like_this').split('_').map((el)=>el.charAt(0).toUpperCase() + el.slice(1)).join('')。我不确定它是否有帮助,但也许你可以在 Visual Studio 中写一些类似的东西? -
@Berci 很遗憾,我不能为此使用 JavaScript 字符串函数,但感谢您的及时回复!
标签: json regex visual-studio-code camelcasing vscode-snippets