1

I'm trying to transform file-name.dto.ts to FileName in a snippet.

${TM_FILENAME_BASE/^(.*)([^.*]).*/${1:/pascalcase}2ドル/}

However, I'm not quite sure how to transform the second capture group or third.

If we don't wrap with a parenthesis, does it mean we don't capture?

 export class ${TM_FILENAME_BASE/^(.)([^.]*).*/${1:/upcase}2ドル/}Input {2ドル},
 export class ${TM_FILENAME_BASE/^(.*).*/${1:/pascalcase}2ドル/}Output {},
Mark
191k32 gold badges555 silver badges577 bronze badges
asked Jan 13, 2021 at 1:52
1
  • I am not clear on what output you want on the Output line? The same thing, just export class FileNameOutput {}? Commented Jan 13, 2021 at 3:27

1 Answer 1

2

For the first line (the Input line), try this:

"export class ${TM_FILENAME_BASE/^([^-]*)-([^.]*).*/${1:/pascalcase}${2:/pascalcase}/}Input {2ドル},"

  1. ${TM_FILENAME_BASE} alone gets you tofile-name.dto

  2. Capture group 1 ^([^-]*) gets you the part before the first -

  3. Match the - but you will ignore it in the output so it doesn't need to be in a capture group.

  4. Capture group 2 ([^.]*) after the - until the first .

  5. The rest .* will match .dto which again will be ignored so it doesn't need to be a capture group, but must be matched - you will effectively replace it with nothing.

Replacing with the transform: ${1:/pascalcase}${2:/pascalcase} so the first letter of both capture groups will be capitalized, the rest lower case.

On the Output line, if you are looking for this result:

export class FileNameOutput {}

use

"export class ${TM_FILENAME_BASE/^([^-]*)-([^.]*).*/${1:/pascalcase}${2:/pascalcase}/}Output {},"


Just in case you don't realize it, in your code:

export class ${TM_FILENAME_BASE/^(.)([^.]*).*/${1:/upcase}2ドル/}Input {2ドル},

that last {2ドル} is NOT referring to any capture group - it is outside any transform. It is only referring to a tabstop - where your cursor will go. Let me know if it is your intention that that final {2ドル} actually be a transformed capture group.

answered Jan 13, 2021 at 3:23
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I now completely understood how it is working :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.