[英]How to use Regex to 'capitalize and replace' in Visual Studio Code's snippets?
I want to create a snippet on Visual Studio Code.我想在 Visual Studio Code 上创建一个片段。
I tried to manually join the Regex but it never worked like my expect:我试图手动加入正则表达式,但它从来没有像我预期的那样工作:
input: idss-static-frame.spec
输入:
idss-static-frame.spec
expected result: IdssStaticFrame
预期结果:
IdssStaticFrame
my Regex: ${TM_FILENAME_BASE/((\\w+(?=\\-))*(\\w+(?=\\.))*)((\\-)*)/${1:/capitalize}/g}
我的正则表达式:
${TM_FILENAME_BASE/((\\w+(?=\\-))*(\\w+(?=\\.))*)((\\-)*)/${1:/capitalize}/g}
actual result: IdssStaticFrame.spec
实际结果:
IdssStaticFrame.spec
I couldn't remove .spec
string我无法删除
.spec
字符串
For this kind of filenames, you may use对于这种文件名,您可以使用
"${TM_FILENAME_BASE/(\\w+)(?:-|\\.\\w+$)/${1:/capitalize}/g}",
See the regex demo查看正则表达式演示
Details细节
(\w+)
- Group 1: one or more word chars (\w+)
- 第 1 组:一个或多个单词字符(?:-|\.\w+$)
- -
or .
(?:-|\.\w+$)
- -
或.
+ 1 or more word chars at the end of string. You may use您可以使用
"${TM_FILENAME_BASE/([^-]+)(?:-|\\.\\w+$)/${1:/capitalize}/g}",
To match file names that contain chars other than just word chars as [^-]+
matches 1 or more chars other than -
.匹配包含除单词字符以外的字符的文件名,因为
[^-]+
匹配除-
以外的 1 个或多个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.