VSCode 片段,将下划线分隔的小写字符串转换为 CamelCase?

VSCode snippet, transform lowercase string delimited by underscores into CamelCase?

我正在 VSCode 中编写自定义片段,以帮助我轻松定义自定义 class 方法。我需要能够输入一个字符串 'formatted_like_this' 并让正则表达式在某些地方转换该字符串,使其变为 'FormattedLikeThis'?

要在 php.json 中编写的自定义代码段:(请参阅 'NEED HELP WITH REGEX HERE' 了解我正在努力的地方)

"New Custom Class Method For Variable": {
    "prefix": "contcmpffv",
    "body": [
        "protected $ = null;",
        "public function get${NEED HELP WITH REGEX HERE}()",
        "{",
        "\t[=11=]",
        "}"
    ],
    "description": "Controller Class Method Public Function For Variable"
}

我想要的工作流程: 1. 输入contcmpffv 2. 出现匹配片段提示时按回车键 2. 片段提示是我 $1

期望的输出(在提示输入 $1 时输入 "test_input_string"):

protected $test_input_string = null;
public function getTestInputString()
{
    *cursor resolves here (due to [=12=])*
}

尝试:

"body": [
    "protected $ = null;",
    "public function get${1/(.*)/${1:/pascalcase}/}()",
    "{",
    "\t[=10=]",
    "}"
],

它使用了未记录的 pascalcase 转换——它已经存在了一段时间。在这种情况下,它会为您完成所有工作。

如果没有pascalcase:

,这就是你可以使用的
"public function get${1/([^_]*)_*/${1:/capitalize}/g}()",