variables - Visual Studio Code Snippet Variable Transform not working
问题描述
I'm trying to make a snippet that inserts the last two directorys of the current filepath.
My code:
${TM_DIRECTORY/\\(.*)\\([a-zA-Z]+)\\([a-zA-Z]+)/$1\\$2/}
So when Filepath is
"...\htdocs\projectname\src"
the output should be
"projectname\src"
.
But instead I get this result:
${TM_DIRECTORY/(.*)\\([a-zA-Z]+)\\([a-zA-Z]+)/$1/}
What am I doing wrong?
解决方案
问题:
问题是代码转换 \\
为\
. 例如,如果你想写\w
,那么你必须写\\w
在片段中。
同样的方式.. 你必须写\\\\
在片段 json 中,这样它才能转换成//
.
解决方案:
${TM_DIRECTORY/.*?\\\\([a-zA-Z]+\\\\[a-zA-Z]+)$/$1/}
或者,我认为您应该使用\w
,而不是[a-zA-Z]
因为目录名称可以包含一些字符,例如-
or_
等。
${TM_DIRECTORY/.*?\\\\(\\w+\\\\\\w+)$/$1/}
推荐阅读
- postgresql - Postgres 问题(无法连接数据库,角色不存在)
- python-3.x - 在 python 中使用或在 .feature 文件中表现
- java - 如何使用 Joda-Time 计算两个日期之间的年数、月数和天数
- php - 使用 laravel 下载和删除文件时弹出不来
- php - Windows 中是否存在根文件系统,尤其是在 Windows 10 中?
- ios - 在飞行模式下,CTCarrier 中的 isoCountryCode 不返回 nil
- sql - 无法连接到 AWS 中的 SQL 数据库(无法访问服务器)
- java - OpenCV VideoCapture 从视频中删除 alpha 通道
- javascript - 如何使用谷歌应用脚本获取谷歌表格中特定列的最后一个单元格?
- node.js - NodeJS - 从 java 密钥库文件中导出私钥