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?
Problem:
The issue is the code converts \\
to \
. For example if you want to write \w
, then you have to write \\w
in snippet.
The same way.. You have to write \\\\
in snippet json, so that it shall convert into //
.
Solution:
${TM_DIRECTORY/.*?\\\\([a-zA-Z]+\\\\[a-zA-Z]+)$/$1/}
or, I think you should use \w
instead of [a-zA-Z]
because the directory name can contain some characters like -
or _
etc.
${TM_DIRECTORY/.*?\\\\(\\w+\\\\\\w+)$/$1/}