Search code examples
visual-studio-codecode-snippetsvscode-snippets

VS code snippet transfrom


The filename is currently filename.dto.ts

I'm trying to transform filename.dto.ts to FilenameInput or FilenameOutput

However, it seems this is not a way to select the second group using regex.

How can I properly select the second regex group and transform it?

export class ${TM_FILENAME_BASE/^(.)|(.dto)$/${1:/upcase}$2/}Input {}
export class ${TM_FILENAME_BASE/(.dto)//}Output {}`

Solution

  • Try this:

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

    Your first capture group is everything up to the first ..

    Then you need to match everything else .* will match .dto (and don't replace it with anything since you don't want it in your result).

    You do not need a second capture group but the previous version I showed did have a capture group 2 (but it wasn't transformed) and it looked like:

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