【发布时间】:2018-06-05 11:51:25
【问题描述】:
我正在尝试编写 VSCode sn-p 以使用本地 Windows 存储库路径作为基础来填充远程存储库路径,但在语法上有些吃力,有人可以帮忙吗?
"MetaData Snippet": {
"prefix": "META",
"body": [
"<#",
" .SYNOPSIS",
" ${1:Enter general synopsis of the type of script}",
"",
" .DESCRIPTION",
" ${2:Short description of what the script will do}",
"",
" .PARAMETER ${3:ParameterNameHere}",
" ${4:Description of the parameter}",
"",
" .EXAMPLE",
" ${5:Example of how to use the code and also expected output}",
"",
" .NOTES",
" VSTS: ${7:$TM_FILEPATH/(.)(:\\)(.*)(\\TSO NH)//g}",
"",
" | Author | QC | VSTS Story ID | Release Date |",
" -----------------------------------------------------------------------------",
" | ${8:Author Name} | ${9:Name of reviewer} | ${10:Story Number} | $CURRENT_DATE/$CURRENT_MONTH/$CURRENT_YEAR_SHORT |",
"#>"
],
"description": "MetaData Snippet"
}
示例路径:c:\Users\USERNAME\git\Cloud and Automation\.vscode\test.ps1
基本上我想去掉c:\Users\USERNAME\git\,剩下的我想用/替换\字符。
我知道我的语法是错误的,但我不确定我对正则表达式的理解是否足够好并且无法弄清楚:(
总结一下我想转:
c:\Users\USERNAME\git\Cloud and Automation\.vscode\test.ps1
进入:
Cloud and Automation/.vscode/test.ps1
【问题讨论】:
-
如果您需要正则表达式方面的特别帮助,只需输入您开始使用的示例行,以及您希望将其转换为的内容。您只是想在字符串中将 \ 替换为 / 吗?
-
这就是我想要的... 当前:c:\Users\USERNAME\git\Cloud and Automation\.vscode\test.ps1 结果:Cloud and Automation/.vscode/test .ps1
-
看起来不错。我不知道 VS,但可以在 python 中快速创建一个 4 行解决方案,但我怀疑有 VS 技能的人很快就会回答这个问题。如果没有,请发表评论,我可以输入我的 python 答案,你可以看到正则表达式是如何工作的。
-
是的,我认为这会有所帮助,至少这样我可以理解逻辑并且可以从那里弄清楚。这是我使用正则表达式的地方: (^.*Cloud)|(\) 这似乎匹配 2 个组(Group1: 'file path' & Group2: '\'),我只是失败了变换。
-
酷,我会回答的
标签: regex visual-studio-code code-snippets