试试这个:
"${TM_DIRECTORY/.*\\\\(.*)\\\\(.*)$/$1\\/$2/}/${TM_FILENAME}"
并看到 在vscode片段中转义 。你有一个 . 在那里 .vscode ,所以你可能也必须适应它 - 只需将一个转义期间添加到第二个捕获组 (\..*) 或者更多的反斜杠,但你可能根本不需要它。
.
.vscode
(\..*)
虽然这在python而不是VS中,你可以看到正则表达式在行动。根据OP在评论中的请求,这是python中的示例。
import re data = r"c:\Users\USERNAME\git\Cloud and Automation\.vscode\test.ps1" path = re.sub(r".*git\\", "", data) #strip up to git fixed_path = re.sub(r"\\", "/", path) #replace backslashes with slashes print(fixed_path)
请注意,我正在逃避 \ 这可能是你遇到的一部分。我选择剥离字符串而不是尝试捕获它的一部分,有时它更容易这样:)
\
输出:
Cloud and Automation/.vscode/test.ps1