2

I need your help, I am building a snippets, but I need to transform the path of the file which is this:

D:\Project\test\src\EnsLib\File\aaa\bbb

and I need it to be like this:

EnsLib\File\aaa\bbb

just leave me from "SRC" forward and replace the \ with points.

Example: D:\Project\test\src\EnsLib\File\aaa\bbb

Result: EnsLib.File.aaa.bbb

that always after the src folder is the starting point

my test regex are these:

"${TM_DIRECTORY/(.*\\\\{4})/$1/}",
"${TM_DIRECTORY/.*src\\\\(.*)\\\\(.*)$/.$2/}.${TM_FILENAME_BASE}",
// "${TM_DIRECTORY/.*\\\\(.*)\\\\(.*)$/$1.$2/}.${TM_FILENAME_BASE}",
// "${RELATIVE_FILEPATH/\\D{4}(\\W)\\..+$/$1/g}",
// "${TM_DIRECTORY/(.*src\\\\)//g}.${TM_FILENAME_BASE}",
// "${RELATIVE_FILEPATH/(\\D{3})\\W|(\\..+$)/$1.$2/g}",
// "${RELATIVE_FILEPATH/\\W/./g}",
4
  • Do you want to say bbb is the file name here? Well, try "${TM_FILEPATH/^.*?\\\\src\\\\|(\\\\)/${1:+.}/g}" Commented Apr 17, 2021 at 17:32
  • thanks. but bbb is a folder. I just need the folders. If you could help me with that, I would appreciate it Commented Apr 17, 2021 at 17:51
  • 1
    Aha, so try "${TM_DIRECTORY/^.*?\\\\src\\\\|(\\\\)/${1:+.}/g}" Commented Apr 17, 2021 at 17:52
  • How does `\\\` work? Where did you find the docs for that? Thanks. Commented Dec 14, 2022 at 14:56

1 Answer 1

2

It seems you want

"${TM_DIRECTORY/^.*?\\\\src\\\\|(\\\\)/${1:+.}/g}"

The regex is ^.*?\\src\\|(\\), it matches

  • ^ - start of string
  • .*? - any zero or more chars other than line break chars, as few as possible
  • \\src\\ - \src\ string
  • | - or
  • (\\) - Group 1 ($1): a \ char.

If Group 1 matches, the replacement is a ., else, the replacement is an empty string, i.e. the text from the start of string till \src\ is simply removed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.