VS 代码片段中的变量转换问题

Facing problem in Variable Transformation in VS Code snippets

我有以下 VS Code

的全局片段代码
"prints formated path": {
    "prefix": "pp",
    "body": [
        "$BLOCK_COMMENT_START",
        "File Path ->     \"${TM_FILEPATH/\///g}\"",
        "$BLOCK_COMMENT_END",
    ],
    "description": "prints path"
},

以上片段的输出是

"""
File Path ->     "D:\tp\New folder (6). Chapter 4 Packaging\my_package\test.py"
"""

预期输出为

"""
File Path ->     "D:/tp/New folder (6)/4. Chapter 4 Packaging/my_package/test.py"
"""

其实我想用'/'

替换'\'

在网络上搜索了太多之后,我找到了 this page which talks about Variable Transformation in VS Code,但它对我没有帮助。 如果您知道问题的解决方案,请提出建议

问题是正则表达式的解析,你必须添加一个捕获组来识别反斜杠并且你必须转义替换斜杠

  "prints formated path": {
    "prefix": "pp",
    "body": [
        "$BLOCK_COMMENT_START",
        "File Path ->     \"${TM_FILEPATH/(\\)/\//g}\"",
        "$BLOCK_COMMENT_END",
    ],
    "description": "prints path"
  }