Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...