json - VSCode片段,将下划线分隔的小写字符串转换为CamelCase?
问题描述
我在VSCode中编写了一个自定义片段来帮助我轻松定义自定义类方法。我需要能够输入一个字符串'formatted_like_this'并在某些地方使用正则表达式转换该字符串,使其变为'FormattedLikeThis'?
要在 php.json 中编写的自定义代码段:(请参阅“需要帮助 REGEX HERE”了解我遇到的问题)
"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}()",
推荐阅读
- spring - 如何在hibernate中映射数据库结构
- python - 错误 - JSONDecodeError:预期值:第 1 行第 1 列(字符 0)
- ios - iOS 如何将凭据添加到 ASCredentialIdentityStore
- django - 我应该使用 uWSGI 吗?
- python - docker化时pip要求不匹配
- bash - bash - 将变量从脚本加载到主 shell
- spring-boot - 如何实现多后端服务和解耦架构的单点登录
- python - django 如何在 HTML 中仅使用 {% url ' x' %} 发出 POST 请求
- google-cloud-platform - 谷歌云:如何列出 GCP 中所有项目的所有服务帐户
- java - 使用NIO开发http服务时遇到的问题