Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
597 views
in Technique[技术] by (71.8m points)

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 {}`

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 {}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...